面试题答案
一键面试function myNew(constructor, ...args) {
// 创建一个新对象,其原型指向构造函数的原型
let newObj = Object.create(constructor.prototype);
// 使用构造函数初始化新对象,并将this指向新对象
let result = constructor.apply(newObj, args);
// 如果构造函数返回的是一个对象,则返回该对象,否则返回新创建的对象
return (typeof result === 'object' && result!== null)? result : newObj;
}