js 實現一個new

js實現一個newapp

function _new(fn, ...arg) {
    const obj = Object.create(fn.prototype);
    const ret = fn.apply(obj, arg);
    return ret instanceof Object ? ret : obj;
}
相關文章
相關標籤/搜索