次のような 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;
})();