如何使用调用提供的函数上下文执行此匿名函数?
function test(text) {
this.first = 'test';
console.log(this.first);
}
(function(val){
return function(val) {
console.log(this.first);
}
}()).call(test)
最佳答案
我没有包含 var self = this;在进入返回函数之前:
(function(val){
var self = this; //add this line
return function(val) {
console.log(self.first);
}
}()).call(test)
关于javascript - 从函数调用带有 'this' 的匿名函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24976961/