<script type="text/javascript">
//js的继承实现
function Person() {// 定义基类的属性和方法
this.name;
this.age;
this.say = function () {
alert('my name is:' + this.name);
}
this.showAge = function () {
alert('my age is:' + this.age);
}
}
function Stu() {// 定义派生类
Person.call(this);//派生类继承基类的所有属性和方法
this.showSchool = function () {// 派生类的特有方法
alert('my school is:'+this.school);
}
}
var s2 = new Stu();
s2.age = 18;
s2.showAge();
s2.school = "BJ";
s2.showSchool();
</script>
javascript实现继承
最新推荐文章于 2024-09-08 22:14:29 发布