箭头函数的特点

function a() {
    return () => {
        return () => {
        	console.log(this)
        }
    }
}
console.log(a()()())

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

猜你喜欢

转载自blog.csdn.net/LuckXinXin/article/details/107706372
今日推荐