function myNew(construct,...args){
let obj = {};
obj.__proto__ = construct.prototype
const r = construct.call(obj,...args)
return r instanceof Object ? r : obj
}
模拟new实现
阅读 114
2023-03-26
function myNew(construct,...args){
let obj = {};
obj.__proto__ = construct.prototype
const r = construct.call(obj,...args)
return r instanceof Object ? r : obj
}
相关推荐
精彩评论(0)