实现如下:
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
}
}
实现如下:
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
}
}
本文标题:new源码实现
本文链接:https://www.haomeiwen.com/subject/gvprhltx.html
网友评论