将函数传递给属性

时间:2011-11-09 22:32:42

标签: javascript oop

我想知道如何将函数设置为方法:

function myfunc(){
   this.method = function() {};
   this.method2 = function (){this.method();}
}

这样我才能做到这一点

obj=new myfunc();
obj.method=function(){//otherthings};

执行method2时,也会执行新方法。

更新:它运行正常,没问题

1 个答案:

答案 0 :(得分:2)

是的,这正是你做的。

相关问题