很简单,直接看例子:学生继承自人
// 父类构造函数
function Person(name, age) {
this.name = name;
this.age = age;
}
// 子类构造函数
function Student(no) {
this.no = no;
}
// 指定子类prototype,注意是new Person(),而不是Person哦,后续文章详解
Student.prototype = new Person();
// 此处new 一个 Student的时候,student 就拥有包含Person属性在内的三个属性
// 以下行输出 {name:undefined,age:undefined,no:undefined}
var student = new Student();
// 父类构造函数
function Person(name, age) {
this.name = name;
this.age = age;
}
// 子类构造函数
function Student(no) {
this.no = no;
}
// 指定子类prototype,注意是new Person(),而不是Person哦,后续文章详解
Student.prototype = new Person();
// 此处new 一个 Student的时候,student 就拥有包含Person属性在内的三个属性
// 以下行输出 {name:undefined,age:undefined,no:undefined}
var student = new Student();