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

箭头函数作为匿名函数,是不能作为构造函数的,不能使用new

1.普通函数的构造对象

# demo.js
var A = function(){}
var a = new A();

→ node demo.js
image.png

2.箭头函数的构造对象

# demo.js
var A = () => {}
var a = new A();

→ node demo.js
image.png

箭头函数不绑定arguments,取而代之用rest参数

# demo.js
function A(){
  console.log(arguments);
}

var B = ()=>{
  console.log(arguments);
}

var C = (...c)=>{
  console.log(c);
}
A(1, 2, 3);
B('one', 'two', 'three');
C('一', '二', '三');

→ node demo.js
image.png

箭头函数没有原型属性

# demo.js
var A = ()=>{}

function B(){}

console.log(A.prototype);
console.log(B.prototype);

→ node demo.js
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容