假设我有一组看起来像这样的 js:
function a() {
this.meow = 0;
var go = setTimeout(function() {
this.parent.meow++;
}, 500);
}
var woof = new a();
为什么不woof.meow
增加,如果我引用错误,那么为什么会这样:
(function() {
this.meow = 'woof';
var go = setTimeout(function() {
alert(this.parent.meow);
},500);
return true;
})();
更令人困惑的是为什么这不起作用:
(function() {
this.meow = 0;
var go = setTimeout(function() {
alert(this.parent.meow++);
},500);
return true;
})();