new绑定是JavaScript中this绑定的最高优先级规则,当函数通过new调用时,this自动绑定到新创建的实例对象上,且覆盖显式和隐式绑定;箭头函数不可被new调用。

在 JavaScript 中,new 绑定是确定 this 值的四种绑定规则之一(其他为默认、隐式、显式绑定)。当你用 new 调用一个函数时,JavaScript 引擎会自动执行以下操作,并将 this 绑定到新创建的对象上:
new 绑定的核心步骤
调用形如 new Foo() 的表达式时,引擎内部会:
- 创建一个全新的空对象(即实例)
- 将该对象的
[[Prototype]]链接到Foo.prototype - 将
this绑定到这个新对象,并执行Foo函数体 - 若函数没有显式返回对象,则默认返回这个新对象
构造函数中 this 指向新实例
你不需要手动指定 this,new 关键字会自动完成绑定。只要函数被 new 调用,其内部的 this 就一定指向新生成的实例对象。
例如:
立即学习“Java免费学习笔记(深入)”;
function Person(name) {this.name = name; // this 指向 new 创建的对象
this.sayHello = function() {
return `Hello, I'm ${this.name}`;
};
}
const alice = new Person('Alice');
console.log(alice.name); // 'Alice'
console.log(alice.sayHello()); // 'Hello, I'm Alice'
注意:箭头函数不能作为构造函数
箭头函数没有自己的 this,也不支持 new 调用。尝试 new (() => {}) 会抛出 TypeError: xxx is not a constructor。因此,只有普通函数(有 prototype 属性且 [[Construct]] 内部方法存在)才能参与 new 绑定。
new 绑定的优先级最高
当多种绑定规则同时存在时,new 绑定的优先级高于显式绑定(call/apply/bind)和隐式绑定。例如:
console.log(this);
}
const bound = Foo.bind({ x: 1 });
new bound(); // this 指向新对象,不是 {x: 1} —— new 绑定覆盖了 bind 的绑定


















