js实现new

function New(fn,...args){
    let obj={}
    obj.__proto__=fn.prototype     
    let result=fn.apply(obj,args)
    if(typeof  result==='object'||typeof  result==='function'){
          return result
    }
    return obj
}        

  

posted @ 2019-07-29 17:31  dawn~monster  阅读(120)  评论(0编辑  收藏  举报