new源码实现
2021-03-28 本文已影响0人
玲儿珑
实现如下:
function Func(){}
let func = new Func()
function New (fn) {
let obj = new Object
obj.__proto__ = fn.prototype
let result = fn.call(obj)
if ( typeof(result) === 'object' ) {
return result
} else {
return obj
}
}