JS通过原型实现继承和隔离 圣杯模式

367 阅读1分钟
//圣杯模式
function Teacher(){
    this.name = 'Mr. Li',
    this.tSkill = 'JAVA'
}
//公共原型
Teacher.prototype = {
    pSkill: 'JS'
}
let teacher = new Teacher()
console.log(teacher)

function Buffer(){}
Buffer.prototype = Teacher.prototype
let buffer = new Buffer()

function Student(){
    this.name = 'Mr. Wu'
}
Student.prototype = buffer
Student.prototype.age = 19
Student.prototype.sex = '女'
let student = new Student()

console.log(student)
console.log(student.name)
console.log(student.age)
console.log(student.sex)
console.log(student.pSkill)