1. function myNew(Obj, ...args) {
    2. let obj = Object.create(Obj.prototype);//使用指定的原型对象及其属性去创建一个新的对象
    3. let ret = Obj.apply(obj,args); // 绑定 this 到obj, 设置 obj 的属性
    4. if ((typeof ret === "object" || typeof ret === "function") && ret !== null) {
    5. return ret;
    6. }
    7. return obj; //确保构造器总是返回一个对象
    8. }
    9. function Foo(name, age) {
    10. this.name = name;
    11. this.age = age
    12. }
    13. let tom = new Foo('tom', 18) // {name: "tom", age: 18}
    14. let kim = myNew(Foo, 'kim', 20) //{name: "kim", age: 20}