原型链继承题目

164 阅读1分钟

下面结果是什么?

function DogFactory(color) {
    this.color = color
    this.sayHi = function(){
        console.log('Hi')
    }
    this.showColor = function(){
        console.log(this.color)
    }
}
DogFactory.prototype.sayHi = function(){
    console.log('Ho')
}
DogFactory.prototype.type = 'dog'


var dog1 = new DogFactory('Black')
var dog2 = new DogFactory('White')


dog1.sayHi()
dog1.showColor()
dog1.type = 'mini dog'
console.log(dog1.type)
console.log(dog1.__proto__.type)


dog2.sayHi()
dog2.showColor()
console.log(dog2.type)