new调用时this绑定为新创建的对象:引擎先创建空对象,将其[[Prototype]]指向构造函数prototype,再以该对象为this执行构造函数;箭头函数无this且不可用作构造函数。

在 JavaScript 中,new 调用时的 this 绑定是由引擎自动完成的:它会创建一个新对象,并将该对象作为构造函数内部的 this 值。
new 调用时 this 的绑定过程
当你写 new Foo(),JavaScript 引擎会按以下步骤执行:
- 创建一个空的普通对象(即
{}) - 将该对象的
[[Prototype]]指向Foo.prototype - 以这个新对象为
this,调用Foo函数(即Foo.call(newObj, ...args)) - 若
Foo显式返回一个对象,则返回该对象;否则返回新创建的对象
constructor 内部的 this 就是 new 出来的实例
这意味着,在构造函数体内,this 不是全局对象、也不是调用者,而是那个刚被创建、且原型已正确设置的对象:
function Person(name) {
this.name = name; // this 指向 new 出来的实例
this.say = function() {
return 'I am ' + this.name;
};
}
const p = new Person('Alice');
console.log(p.name); // 'Alice'
console.log(p.say()); // 'I am Alice'
console.log(p instanceof Person); // true
注意:箭头函数没有自己的 this,也不受 new 影响
如果构造函数内部用了箭头函数,它的 this 是词法继承外层作用域的,**不会被 new 改变**:
立即学习“Java免费学习笔记(深入)”;
- 箭头函数内的
this始终等于定义时所在函数的this - 所以不能用箭头函数作为构造函数(调用
new会报错) - 在普通构造函数中,箭头函数里的
this通常指向外层函数的this(也就是实例),但这不是 new 绑定的结果,而是词法绑定
手动模拟 new 的行为有助于理解 this 来源
你可以用普通函数模拟 new 的核心逻辑:
function myNew(constructor, ...args) {
const obj = Object.create(constructor.prototype);
const result = constructor.apply(obj, args);
return (result !== null && typeof result === 'object') ? result : obj;
}
这里关键点是:constructor.apply(obj, args) —— 正是这一步把 obj 绑定为 this。


















