复制代码 代码如下:
<script type="text/javascript">
//创建基类
function Person(name, age) {
this.name = name;
this.age = age;
}
//通过原型方式给基类添加函数(这样可以服用此函数)
Person.prototype.showName = function () {
alert(this.name);
}
//创建子类
function Student(name, age, score) {
this.score = score;
Person.call(this,name,age);
}
//把父类的实例赋值给子类的原型
Student.prototype = new Person();
//通过原型方式给子类添加函数(这样可以服用此函数)
Student.prototype.showScore = function () {
alert(this.score);
}

//以下为使用
var student = new Student("zhangsan", 22, 100);
student.showName();
student.showScore();

var stu = new Student("lisi", 25, 200);
stu.showName();
stu.showScore();
</script>
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com