function myNew(Constrcutor, ...args) { // 1.创建一个新对象 let newObj = {}; // 2.将新对象的__proto__指向构造函数的原型 Object.setPrototypeOf(newObj, Constrcutor.prototype); // 3. 将构造函数内部的this指向新对象 let res = Constrcutor.apply(newObj, args); // 4.判断构造函数返回值是否为对象,如果为对象就使用构造函数返回的值,返回刚创建的新对象 return res instanceof Object ? res : newObj; }