new

作者: bestCindy | 来源:发表于2020-10-20 21:25 被阅读0次
    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);
    

    相关文章

      网友评论

          本文标题:new

          本文链接:https://www.haomeiwen.com/subject/iokjmktx.html