new

2020-10-20  本文已影响0人  bestCindy
function fn(name, age) {
    this.name = name;
    this.age = age;
}

function newOperator(cons) {
    let obj = Object.create(cons.prototype);

    let newArgs = [...arguments].splice(1)
    cons.apply(obj, newArgs);

    return obj;
}

let newObj = newOperator(fn, "Cindy", "18");
console.log(newObj);
上一篇下一篇

猜你喜欢

热点阅读