function a() {
return () => {
console.log(this)
}
console.log(a()()())
箭头函数其实是没有 this的,这个函数中的 this只取决于他外面的第一个不是箭头函数的函数的 this。在这个例子中,因为调用 a符合前面代码中的第一个情况,所以 this是 window。并且 this一旦绑定了上下文,就不会被任何代码改变。
function a() {
return () => {
return () => {
console.log(this)
}
}
}
console.log(a()()())
箭头函数其实是没有 this的,这个函数中的 this只取决于他外面的第一个不是箭头函数的函数的 this。在这个例子中,因为调用 a符合前面代码中的第一个情况,所以 this是 window。并且 this一旦绑定了上下文,就不会被任何代码改变。