// 模拟new
// 实现继承的过程
// 创建对象 => 继承目标函数的prototype => 绑定this => 返回
function Dog (name){
this.name = name
}
Dog.prototype.sayIt = function(){
console.log(this.name)
}
function _new(fun, ...args){
let rel = Object.create(fun.prototype)
let obj = fun.apply(rel, args)
return obj instanceof Object ? obj : rel
}
let newDog = _new(Dog, '我是一只可爱的小狗')
newDog.sayIt()