箭头函数与普通函数区别

let a = ()=>{}

let b = function () {}

 

 

1.No own this bindings

Arrow functions do not have their own this value. The value of this inside an arrow function is always inherited from the enclosing scope.

箭头函数没有this值,箭头函数内部的this值总是从作用域链继承得到的。

 

2.Arrow functions do not have a arguments array

In JS arguments array in functions is a special object that can be used to get all the arguments passed to the function. Similar to this, arrow functions do not have their own binding to a arguments object, they are bound to arguments of enclosing scope.

箭头函数没有arguments

let a = ()=>{console.log(arguments)}  // a()

let b = function () {console.log(arguments)} // b()

 

3.Arrow functions are callable but not constructable

If a function is constructable, it can be called with new, i.e. new User(). If a function is callable, it can be called without new (i.e. normal function call).

Functions created through function declarations / expressions are both constructable and callable.

Arrow functions (and methods) are only callable. class constructors are only constructable.

 

let a = ()=>{}          // a()       new a()

let b = function (){} // b()       new b()

posted @ 2020-06-08 19:22  hh9515  阅读(114)  评论(0编辑  收藏  举报