function Parent() {
this.name= '张三',
this.age= 22
}
Parent.prototype.say= function() {
console.log("说话...")
}
function Child() {
Parent.call(this)
this.sex= '男'
}
Child.prototype.sleep= function() {
console.log('睡觉...')
}
Child.prototype= Object.create(Parent.prototype);
Child.prototype.constructor= Child;
const obj= new Child();
console.log(obj.sex)
obj.say()
obj.sleep()
console.log(obj.__proto__ === Child.prototype)
console.log('=========================++++++++++++++++++++++++============================')
function newFn() {
const obj= {}
obj.__proto__= Child.prototype;
Child.call(obj);
return obj;
}
const obj2= newFn();
console.log(obj2.name)
obj2.say()
console