function Person() {}
Person.prototype.name = 'xiaohesong'
Person.prototype.types = ['student']
let p1 = new Person
let p2 = new Person
p1.types.push('man')
console.log(p2.types) // ['student', 'man']
p2.types = ['teacher', 'woman']
console.log(p2.types) // ['teacher', 'woman']
function First() {
this.firstName = 'firstName'
}
First.prototype.getFirstName = function(){
return this.firstName
}
function Second() {
this.secondName = 'secondName'
}
Second.prototype = new First
Second.prototype.getSecondName = function(){
return this.secondName
}
let first = new First
let second = new Second
second.getFirstName() //firstName
second.getSecondName() //secondName
first.getSecondName() // error
second.constructor === First //true
second.__proto__ === Second.prototype
Second.prototype = new First //1
Second.prototype.constructor = Second //2