1
誰能告訴我如何isSharp
是在global context
下面的代碼。我正在關注約翰先進的JS。上下文代表什麼?
http://ejohn.org/apps/learn/#24
function katana(){
this.isSharp = true;
}
katana();
alert(isSharp);
assert(isSharp === true, "A global object now exists with that name and value.");
var shuriken = {
toss: function(){
this.isSharp = true;
}
};
shuriken.toss();
assert(shuriken.isSharp === true, "When it's an object property, the value is set within the object.");
也許您應該在MDN上閱讀[this'關鍵字的介紹](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) – Bergi