This
觀念
重新指向 this
function callName() {
console.log('區域', this.name);
var that = this;
setTimeout(function () {
console.log('全域', this.name);
console.log('區域', that.name);
}, 10);
}
var name = '全域阿婆';
var auntie = {
name: '漂亮阿姨',
callName: callName
// 這裡的 function 指向全域的 function,但不重要
}
auntie.callName();強制指定this的方式
this 與前後文綁定的基本原則
預設綁定
隱含式綁定
顯示綁定
new 關鍵字綁定
this 的判斷步驟
Last updated