function MyNew(fn, ...args) {
var obj = Object.create(null)
Object.setPrototypeOf(obj, fn.prototype)
var result = fn.apply(obj, args)
return result instanceof Object ? result : obj
}
function example(age, name) {
this.age = age
this.name = name
}
MyNew(example,78,'张三')
js的new操作符具体做了什么
最新推荐文章于 2024-11-02 12:42:04 发布