如ClassA.prototype = new ClassB().
就可以说ClassA是ClassB的子类,同时ClassB是ClassA的父类
js中定义一个class其实就是一个function,如
var ClassA = function() {
}
====怎么最近好像老有人问这个?
//子类Studentfunction Student(name,age,sex,phone){
//继承方法
Person.call(this,name,age)
//添加自己的属性
this.sex=sex
this.phone=phone
//添加自己的方法
this.say()
}
//继承父类的属性
for(var i in Person.prototype){
Student.prototype[i]=Person.prototype[i]
}
//重写父类方法
Student.prototype.say()
{
alert(this.phone+' 'this.sex)
}