模拟new实现

function myNew(construct,...args){
  let obj = {};
  obj.__proto__ = construct.prototype
  const r = construct.call(obj,...args)
  return r instanceof Object ? r : obj
}
posted @ 2023-02-08 23:13  hh9515  阅读(20)  评论(0)    收藏  举报