-
箭头函数是匿名函数,不能作为构造函数,不能使用new
let a = () => { console.log(1) } a() new a() // TypeError: a is not a constructor
-
箭头函数不绑定arguments(用于指向调用者传入的所有参数),取而代之用rest参数...解决
function A(a, b, c, d) { console.log(arguments); // [1, 2, 3, 4, callee: ƒ, Symbol(Symbol.iterator): ƒ] } A(1, 2, 3, 4) let B = (...r) => { console.log(r); // [5, 6, 7] } B(5, 6, 7)
-
this的作用域不同
var obj = { name: 'HS', sayName: function () { console.log(this.name); } } var name = 'Window'; var obj1 = { name: 'HH', sayName: () => { console.log(this.name); } } obj.sayName(); // HS obj1.sayName(); // Window
-
箭头函数没有原型属性
var a = () => { return 1; } function b() { return 2; } console.log(a.prototype); // undefined console.log(b.prototype); // {constructor: ƒ}
网友评论