Arrow function's this and normal function's this

Reference blog post: https://www.cnblogs.com/fanzhanxiang/p/8888963.html

 

 

The arrow function itself does not have this, so its internal this is 父执行上下文the this it inherits from. So when calling obj to call func0(), this is window, and the parent execution context is window

name = "window";
var obj = {
name: "obj",
func0: () => {
    console.log(this)
    console.log(this.name);
 },
func1: function() {
    console.log(this)
    console.log(this.name);
 },
}
obj.func0()

 

Guess you like

Origin blog.csdn.net/qq_41083105/article/details/116062537