继承-直接继承prototype属性
<script>
function Person(){
}
Person.prototype.foot = 2;
Person.prototype.head = 1;
function Student(name,no){
this.name=name;
this.no=no;
}
Student.prototype = Person.prototype;
Student.prototype.constructor = Student;
var stu1 = new Student("张三","s001");
alert(stu1.constructor);
alert(stu1.name);
alert(stu1.no);
\
alert(stu1.foot);
alert(stu1.head);
\
alert(Person.prototype.constructor);
\
</script>
继承-prototype属性
<script>
function Person(){
this.foot = 2;
this.head=1;
}
function Student(name,no){
this.name=name;
this.no=no;
}
Student.prototype = new Person();
Student.prototype.constructor = Student;
var stu1 = new Student("张三","s001
alert(stu1.
alert(stu1
alert(stu1.no);
alert(stu1.foot);
alert(stu1.head);
</script>
继承-使用空对象作为中介
<script>
function Person(){}
Person.prototype.foot = 2;
Person.prototype.head = 1;
function Student(name,no){
this.name=name;
this.no=no;
}
var F= function(){};
F.prototype = Person.prototype;
Student.prototype = new F();
var stu1 = new Student("张三","s001");
Student.prototype.constructor = Student;
alert(Person.prototype.constructor);
\