共计 343 个字符,预计需要花费 1 分钟才能阅读完成。
// 创立一个空对象,链接到原型,绑定 this 值,返回新对象
function createNew(){let obj = {}
let constructor = [].shift.call(arguments)
obj.__proto__ = constructor.prototype
let result = constructor.apply(obj,arguments)
return typeof result==='object'?result:obj
}
function People(name,age){
this.name = name
this.age=age
}
let peo = createNew(People,'Allan',22)
console.log(peo.name)
console.log(peo.age)
正文完
发表至: javascript
2021-07-05