javascriptの中で最もよく使われている継承パターンの組み合わせは継承されます.

1062 ワード

 
  
<br>// <br>function Person(name, age) { <br>this.name = name; <br>this.age = age; <br>} <br>// ( ) <br>Person.prototype.showName = function () { <br>alert(this.name); <br>} <br>// <br>function Student(name, age, score) { <br>this.score = score; <br>Person.call(this,name,age); <br>} <br>// <br>Student.prototype = new Person(); <br>// ( ) <br>Student.prototype.showScore = function () { <br>alert(this.score); <br>} <br> <br>// <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>