Copy Code code as follows:
<script type= "Text/javascript" >
To create a base class
function person (name, age) {
THIS.name = name;
This.age = age;
}
To add a function to a base class in a prototype way (so you can take this function)
Person.prototype.showName = function () {
alert (this.name);
}
To create a child class
function Student (name, age, score) {
This.score = score;
Person.call (This,name,age);
}
To assign an instance of a parent class to the prototype of a subclass
Student.prototype = new Person ();
To add a function to a subclass by prototyping it (so you can take this function)
Student.prototype.showScore = function () {
alert (This.score);
}
The following are used
var student = new Student ("Zhangsan", 22, 100);
Student.showname ();
Student.showscore ();
var stu = new Student ("Lisi", 25, 200);
Stu.showname ();
Stu.showscore ();
</script>