中等ES6
0 1

如果new一个箭头函数会怎么样?

【概念释义】

箭头函数不是构造函数:没有 [[Construct]] 内部方法,没有 prototype 属性。对箭头函数使用 new 会抛出 TypeError: xxx is not a constructor

设计意图:箭头函数专用于短回调与词法 this,与 class / 普通 function 构造实例的职责分离。

【基础使用】

javascript
const Foo = () => ({ name: 'bar' });

"qb-hl-comment">// new Foo(); // TypeError: Foo is not a constructor

登录查看完整 1124

回答讨论

暂无讨论,登录后可抢先发言

本题库更多题目(14)