Skip to content
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

es6 8.5 箭头函数 #41

Open
Seasons123 opened this issue Jul 20, 2017 · 1 comment
Open

es6 8.5 箭头函数 #41

Seasons123 opened this issue Jul 20, 2017 · 1 comment

Comments

@Seasons123
Copy link
Owner

1.基本用法
ES6允许使用“箭头”(=>)定义函数。
var f = v =>v ;
上面的箭头函数等同于:
var f = function ( v ) { return v ; }

@Seasons123
Copy link
Owner Author

Seasons123 commented Jul 20, 2017

尤其注意this的指向:
this指向的固定化:函数体内的this对象就是定义时所在的对象,而不是使用时所在的对象。
this指向的固定化的原因:箭头函数根本没有自己的this,导致内部的this就是外层代码块的this。
正因为它没有this,所以也就不能用作构造函数。当然也就不能用call()、applay()、bind()这些方法去改变this的指向,使用这些方法都是无效的。

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

No branches or pull requests

1 participant