Use constructors in JavaScript to implement inherited Code. For more information, see.
The Code is as follows:
// First create the parent class
Function Person (name, age, address ){
This. name = name;
This. age = age;
This. address = address;
}
// Create a subclass
Function Student (score ){
This. score = score;
// You can call the constructor of a function using the call or apply method.
// Call the constructor of the parent class and call the constructor of the Person class through the call method. In this way, the Person object will be initialized in student, and student will have a copy of the Person attribute.
Person. call (this, "zhangsan", 22, "Beijing, China! ");
}
Var student = new stuindent (100 );
Alert (student. address + student. score + "score ");
// The second parameter in the above Person. call method call starts to be the passed data Parameter