<div class="codetitle"> <span><a style="CURSOR: pointer" data="10479" class="copybut" id="copybut10479" onclick="doCopy('code10479')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code10479"> <br><script type="text/javascript"> <br> //Create base class <br>function Person(name, age) { <br>this.name = name; <br>this.age = age; <br>} <br>//Add to base class through prototype Function (so you can take this function) <br>Person.prototype.showName = function () { <br>alert(this.name); <br>} <br>//Create a subclass <br>function Student(name , age, score) { <br>this.score = score; <br>Person.call(this,name,age); <br>} <br>//Assign the instance of the parent class to the prototype of the subclass<br>Student.prototype = new Person(); <br>//Add a function to the subclass through the prototype (so you can use this function) <br>Student.prototype.showScore = function () { <br>alert(this .score); <br>} <br><br>//The following is used<br>var student = new Student("zhangsan", 22, 100); <br>student.showName(); <br>student .showScore(); <br><br>var stu = new Student("lisi", 25, 200); <br>stu.showName(); <br>stu.showScore(); <br></ script> <br> </div>