箭头函数与箭头函数的区别


1.箭头函数不绑定 arguments,取而代之用 rest 参数(…a) => {console.log(a)}解决 

2.箭头函数不能当做 Generator 函数,不能使用 yield 关键字

3.箭头函数没有原型属性:

(()=>{ }).prototype // undefined
(function a(){}).prototype // {constructor: ƒ}


ES6 中新增了箭头函数这种语法,箭头函数以其简洁性和方便获取 this 的特性:

普通函数下的 this:
+ 在普通函数中的 this 总是代表它的直接调用者,在默认情况下,this 指的是 window,
+ 在严格模式下,没有直接调用者的函数中的 this 是 undefined 使用
+ call,apply,bind(ES5 新增)绑定的,this 指的是 绑定的对象
 
箭头函数中的 this:
+ 箭头函数没有自己的 this, 它的 this 是继承而来; 默认指向在定义它时所处的对象(宿主对象),
+ 而不是执行时的对象, 定义它的时候,可能环境是 window,也有可能是其他的。
 

猜你喜欢

转载自blog.csdn.net/qq_38629292/article/details/125800863