2
爲什麼this
關鍵字在下面的代碼表達不同的價值觀?「這個」關鍵字在javascript返回不同
var t = {
a: "a",
b: {
c: "c",
d: function() {
return this;
}
},
f: function() {
return this;
},
g: this
}
var k = t.f(),
l = t.g;
alert(k); // returns [object object] i.e 't'
alert(l); // returns [object DOMWindow] i.e 'window'
http://stackoverflow.com/questions/3127429/javascript-this-keyword?rq=1 – DCoder 2013-02-28 08:08:44