chiyan-lin / code-snippet

the record of something snippety
1 stars 0 forks source link

mock new #12

Open chiyan-lin opened 4 years ago

chiyan-lin commented 4 years ago


function _new (fn, ...arg) {
  const obj = Object.create(fn.prototype)
  const ret = fn.apply(obj, arg)
  return ret instanceof Object ? ret : obj
}