【发布时间】:2018-05-23 04:55:22
【问题描述】:
我在这样的回调中访问了公共值。
function InfoClass() {
var local = 1;
self = this;
}
InfoClass.prototype.myFunction = function (){
this.win.addEventListener('open', function(e){
// I can't use 'this' here.
self.local // So I access common value in callback like this.
});
}
在严格模式之前它可以工作,
但是,现在我需要设置严格模式,所以它显示错误self 没有var。
还有其他方法吗??
【问题讨论】:
-
只需使用箭头函数,以便继承父作用域的
this
标签: javascript strict