Twlig / issuesBlog

MIT License
3 stars 0 forks source link

结合new + 执行上下文 解答箭头函数this指向问题 #50

Open Twlig opened 2 years ago

Twlig commented 2 years ago

问题:

function Person(){
    (()=> {console.log(this)})();
}
Person(); //window 
new Person();//Person{}. 

为何Person()指向window,new Person()指向Person对象?

根据箭头函数的this指向定义时的上下文的this