我们可以在箭头函数上调用new吗?

Can we call new on arrow function?

本文关键字:调用 new 函数 我们      更新时间:2023-09-26

我有一个箭头函数,如下所示:

var Test = () => {}

当我调用:

new Test()

I get back:

VM110:1 Uncaught TypeError: Test is not a constructor(…)(anonymous function) @ VM110:1

我们不能在箭头函数上调用new ?

箭头函数不能用作构造函数:普通函数通过内部方法[[Construct]]和属性prototype来支持new。箭头函数两者都没有,这就是为什么

new (() => {}) 

抛出错误