var obj = { name: 'name', foo: function () { console.log(this); // Object {name: "name"} setTimeout(function () { console.log(this); // Window }, 1000); }, foo2: function () { console.log(this); // Object {name: "name"} setTimeout(() => { console.log(this); // Object {name: "name"} }, 2000); }}為什么settimeout中的函數(shù)this指向window?而箭頭函數(shù)this指向Object是因為settimeout是window對象的方法還是說當做直接調(diào)用一個函數(shù)?
為什么settimeout中的函數(shù)this指向window?
桃花長相依
2018-10-10 13:14:58