//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 use the call method or the apply method to call the constructor of the function
//Call the constructor of the parent class, and call the constructor of the Person class through the call method . This will initialize the Person object in the student, and the student will also have a copy of the Person's attributes
Person.call(this, "zhangsan",22, "Beijing, China!");
}
var student = new Student(100);
alert(student.address student.score "point");
//The second in the above Person.call method call parameters start with the passed data parameters
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn