分析一下箭头语法为什么不能当做构造函数
是因为箭头函数没有 [[Construct]] 。如果通过new调用,就会出错
而且因为既然不能当做构造函数,所以也不存在 prototype 属性
function Person() {}
console.log(Person.prototype); // {constructor: ƒ}
let Animal = () => {};
console.log(Animal.prototype); // undefined
注意点:
- 箭头函数没有自己的 this,而是继承父作用域的 this
- 不支持 call bind,改变 this 指向。
- 不绑定 arguments
- 没有 prototype 属性