function myNew(Ctr, ...args) {
if (typeof Ctr !== "function") {
throw new TypeError("Constructor must be a function");
}
// 创建原始对象
// let obj = {};
// 设置新对象的prototype
// Object.setPrototypeOf(obj, Ctr.prototype);
// 创建原始对象,Object.create可以以参数为prototype创建一个新对象
let obj = Object.create(Ctr.prototype);
const result = Ctr.apply(obj, args);
// 判断一下,防止构造函数指定了返回值
return result !== null &&
(typeof result === "object" || typeof result === "function")
? result
: obj;
}