Skip to content

箭头函数和普通函数的区别 #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Twlig opened this issue Mar 17, 2022 · 0 comments
Open

箭头函数和普通函数的区别 #47

Twlig opened this issue Mar 17, 2022 · 0 comments

Comments

@Twlig
Copy link
Owner

Twlig commented Mar 17, 2022

箭头函数和普通函数的区别

(1)箭头函数语法上比普通函数更加简洁

(2)箭头函数没有自己的this,它里面出现this是继承函数所处上下文中的this(使用call,apply等任何方式都无法改变this的指向)

(3)箭头函数中没有arguments(类数组),只能基于…ARG获取传递的参数集合

(4)箭头函数不能被new函数(因为:箭头函数没有this,也没有prototype)

注:回调函数的this一般指向window

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

讨论见:#50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant