Open MJingv opened 4 years ago
function Parent () {
this.name = 'parent'
}
Parent.prototype.do = function () {
console.log(1)
}
function Child () {
this.name = 'child'
}
Child.prototype = new Parent()
let c = new Child()
console.log(c)
function Parent () {
this.name = 'parent'
}
Parent.prototype.do = function () {
console.log(1)
}
function Child () {
Parent.call(this)
this.name = 'child'
}
Child.prototype = new Parent() //多次调用
let c = new Child()
console.log(c)
function Parent () {
this.name = 'parent'
}
Parent.prototype.do = function () {
console.log(1)
}
function Child () {
Parent.call(this)
this.name = 'child'
}
Child.prototype = Object.create(Parent.prototype)
Child.prototype.constructor = Child
let c = new Child()
console.log(c.__proto__)
用call继承