关于JSthis指向的一道题(你不知道的JS)

var obj = {
    id: "awesome",
    cool: function coolFn() { 
        console.log(this.id);
    }
};
var id = "not awesome"
obj.cool(); // 酷   this指向obj
setTimeout(obj.cool, 100); // 不酷   this指向setTimeout

this谁调用   this指向谁 

posted @ 2021-04-13 14:27  faint33  阅读(31)  评论(0)    收藏  举报