手动实现new方法

107 阅读1分钟
function create(){
    let obj={};
    let constructor=[].shift.call(arguments);
    obj.__proto__=constructor.prototype;
    let result=constructor.apply(obj,arguments);
    return typeof result==="object"?result:obj;
}