是否可能在对象上设置默认函数,以便当我调用 myObj()
时执行该函数?假设我有以下的 func
对象:
function func(_func) {
this._func = _func;
this.call = function() {
alert("called a function");
this._func();
}
}
var test = new func(function() {
// do something
});
test.call();
我想用test()
来代替test.call()
,这可能吗?