JMC*_*pos 2 javascript delegates
我有以下代码
function createDelegate(object, method)
{
var shim = function()
{
method.apply(object, arguments);
}
return shim;
}
this.test = 3;
var pAction = {to: this.test}
this.tmp = createDelegate(this, function()
{
print("in: " + pAction.to);
return pAction.to;
});
print("out: " + this.tmp());
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我得到以下结果
in: 3
out: undefined
Run Code Online (Sandbox Code Playgroud)
有人知道这个的原因吗?
创建委派函数时,必须返回旧函数的结果:
function createDelegate(object, method)
{
var shim = function()
{
return method.apply(object, arguments);
}
return shim;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7575 次 |
最近记录: |