箭头函数和普通函数的区别
2017-11-21 本文已影响23人
桃花島主
箭头函数作为匿名函数,是不能作为构造函数的,不能使用new
1.普通函数的构造对象
# demo.js
var A = function(){}
var a = new A();
→ node demo.js

2.箭头函数的构造对象
# demo.js
var A = () => {}
var a = new A();
→ node demo.js

箭头函数不绑定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

箭头函数没有原型属性
# demo.js
var A = ()=>{}
function B(){}
console.log(A.prototype);
console.log(B.prototype);
→ node demo.js
