function myNew (context) {// 1. 创建一个新对象const obj = new Object();// 2. 根据原型链, 设置空对象的 __proto__ 为构造函数的 prototypeobj.__proto__ = context.prototype;// 执行构造函数, 将其 this 指向 新创建的对象(为这个对象添加属性)const res = context.apply(obj, [...arguments].slice(1));// 判断构造函数执行返回的结果, 原始值则忽略返回新创建的对象, 引用值则返回引用值.return typeof res === 'object' ? res : obj;}
