function myNew(...args) {
const Constructor = args[0]
const o = Object.create(Constructor.prototype)
const res = Constructor.apply(o, args.slice(1))
return res instanceof Object ? res : o
}
// 使用
function P(v) {
this.v = v
}
const p = myNew(P, 1) // P {v: 1}
阅读量:666
点赞量:0
收藏量:0