var name = 'tom';function fn() { this.name = 'jerry'; setTimeout(function () { console.info(this == window); console.info(this.name); }, 1000); }window.fn();var f = new fn();我的理解:setTimeout中匿名函數this指向window,但是console.info(this.name)輸出jerry。不太理解。如果我換一種方式調用fn即var f = new fn();console.info(this.name)輸出tom。以上。多謝。
javascript this指向問題
嗶嗶one
2019-02-06 17:17:25