Possible Duplicate:
Function Arguments Passing and Return
我需要一点帮助
var foo = {
bar: function () {
return this.baz;
},
baz: 1
};
(function () {
return typeof arguments[0]();
})(foo.bar);
此代码段执行时返回“未定义” 有人可以解释一下为什么会这样吗?
最佳答案
您需要使用正确的调用范围。显式设置 foo 作为范围可以得到预期的结果。
var foo = {
bar: function () {
return this.baz;
},
baz: 1
};
(function () {
return arguments[0].call(foo);
})(foo.bar);
关于javascript - 此 JavaScript 代码返回 'Undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11325395/