[Native] to write a class and subclass inherits the prototype chain with a way to understand inheritance relations, prototype understanding

Understand writing a class and subclass inherits the prototype chain way, inheritance relationships, understanding prototype

function Person(name,age){
    this.name=name;
    this.age=age;
}
Person.prototype.study=function(){
    return "学习"
}
function Student(class_,name,age){
    this.class_=class_;
    this.name=name;
    this.age=age;
}
var p1=new Person()
console.log(p1)
Student.prototype=new Person();
var s1=new Student("二班","黎明","16");
console.log(s1)

console.log(s1.name,s1.age,s1.class_,s1.study());

 

Guess you like

Origin www.cnblogs.com/yuanjili666/p/11639828.html