箭头函数不能用 new 调用,因其缺少 [[construct]] 内部方法,无法创建实例、无 prototype 属性、this 为词法绑定不可重置;需构造实例时应使用普通函数或 class。

因为箭头函数没有 [[Construct]] 内部方法,而 new 运算符在执行时,第一步就是检查目标函数是否实现了这个方法。不满足,直接抛出 TypeError: xxx is not a constructor。
核心原因:缺少 [[Construct]] 方法
ECMAScript 规范明确规定,new 调用必须作用于具有 [[Construct]] 内部方法的对象。普通函数(包括函数声明、函数表达式)默认具备该方法;但箭头函数被设计为“仅用于执行逻辑”,语言层面就跳过了对它的实现。
- 没有
[[Construct]]→new无法启动对象创建流程 - 没有
prototype属性 → 即使绕过检查,也无法设置新实例的原型链 - 没有独立的
this绑定机制 → 构造过程依赖this指向新对象,而箭头函数的this是词法继承、不可重绑定的
对比普通函数的 new 执行流程
当你写 new Person(),JS 引擎会:
- 创建一个空对象,并将其
__proto__指向Person.prototype - 以该对象为
this,调用Person函数体 - 若函数无显式返回对象,则自动返回该
this对象
箭头函数无法参与这个流程——它既不能接收新创建的对象作为 this,也不能通过 prototype 影响实例的继承关系。
DMap GL地图JSAPI(dmapgl)开发指南。用于编写、审查、调试 DMap 地图 API 代码,涵盖地图初始化、覆盖物渲染、图层管理、事件处理、控件交互等任务。当用户提及 dmap、dmapgl、jsapi‑gl 或相关地图开发需求时自动触发。
常见错误示例
以下代码都会报错:
const Foo = () => {};
new Foo(); // TypeError: Foo is not a constructor
const Bar = (name) => { this.name = name };
new Bar('test'); // 同样报错,且 this.name = name 实际赋值到全局/外层 this 上
即使函数体里写了 this.xxx = yyy,也不会生效,因为这里的 this 不是新实例,而是外层作用域的 this(比如模块顶层的 globalThis 或严格模式下的 undefined)。
替代方案:需要构造行为就用普通函数
如果要创建实例并挂载属性或方法,应使用传统函数形式:
- 函数声明:
function Person(name) { this.name = name; } - 函数表达式:
const Person = function(name) { this.name = name; }; - ES6 类:
class Person { constructor(name) { this.name = name; } }
这些都具备 [[Construct]],支持 new,也拥有可配置的 prototype。










