一、箭头函数中的this指向
箭头函数的this指向通常有两种情况
- 如果箭头函数处在一个普通函数之中,那么他的this指向与包裹他的外层函数的this指向一致。
- 其他情况下箭头函数中的this都指向window
let obj = {
fn:function(){
console.log('我是普通函数',this === obj) // true
return ()=>{
console.log('我是箭头函数',this === obj) // true
}
}
}
console.log(obj.fn()())
let obj = {
fn:()=>{
console.log(this === window);
}
}
console.log(obj.fn())
// true