new 做了什么

new 做了什么

function myNew(fn, ...args){
    let obj = {}
    obj.__proto__ = fn.prototype
    let result = fn.call(obj, ...args)
    return typeof result === 'object' ? result : obj;
}    

 

posted @ 2020-03-04 10:17  EthanCheung  阅读(81)  评论(0编辑  收藏  举报