调用匿名函数'this'从函数
Call anonymous function with 'this' from function
如何在调用中提供的函数的上下文中执行这个匿名函数?
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)
我相信你得到了this
在test
与test.prototype
的背景下的价值。
相关文章:
- 在另一个函数中使用变量this
- JavaScript 中的嵌套函数和 “this” 关键字
- javascript中对象构造函数中的var属性与this.properties
- 函数中this和var之间的区别
- 在JavaScript类型的函数中避免self-this
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- jQuery使用ajax自动完成问题-TypeError:this.source不是函数
- 为什么在这种情况下,“This”确实充当javascript函数中的私有成员
- TypeError:this.getAttribute不是一个函数-javascript
- CasperJS error - undefined 不是函数 (this.waitForUrl)
- AngularJs服务函数this()
- 内联onclick函数(this)不调用jQuery方法
- jQuery自定义函数- this.each
- 为什么在构造函数'this'DOMWindow
- 调用匿名函数'this'从函数
- Javascript检查函数(this)的长度
- 如何使用onchange="函数(this.value)
- 改变一个函数"this"值
- javascript构造函数this is't绑定正确
- JS原型函数'this'混乱