Skip to content
On this page

#手写new

js
function myNew(constructor,...args) {
    const obj = {};
    obj.__proto__ = constructor.prototpye;
    const result = constructor.apply(obj,args);
    return result instanceof Object ? result : obj;
}