JavaScript中使用构造函数实现继承的代码

时间:2010-08-12    点击:77   
复制代码 代码如下:

//首先创建父类
function Person(name, age, address) {
this.name = name;
this.age = age;
this.address = address;
}
//创建子类
function Student(score) {
this.score = score;
//可以用call方法或者是apply方法调用函数的构造函数
//调用父类的构造函数,通过call方法调用Person类的构造函数。这样就会在student中初始化Person对象,student也就有了Person的属性的副本
Person.call(this,"zhangsan",22,"中国北京!");
}

var student = new Student(100);
alert(student.address + student.score + "分");


//上述Person.call方法调用中第二个参数开始为传递的数据参数
基于jquery的实现简单的表格中增加或删除下一行
Jquery从头学起第四讲 jquery入门教程
jQuery中的bind绑定事件与文本框改变事件的临时解决方法
基于jquery的兼容各种浏览器的iframe自适应高度的脚本
jquery实用代码片段集合
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved