首页 > 编程语言 > 详细

javascript类继承

时间:2014-06-01 17:11:13      阅读:418      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
function extend(subClass, superClass) {
    var f = function() {};
    f.prototype = superClass.prototype;
    subClass.prototype = new f();
    subClass.superClass = superClass.prototype;
}

var parent = function (name, age) {
    this._name = name;
    this._age = age;
};

parent.prototype.show = function () {
    console.info(this._name + " : " + this._age);
};


var son = function(name,age,height) {
    this._height  = height;
    son.superClass.constructor.call(this,name,age);
};

extend(son, parent);
//这里没有重写父类也就是parent的show方法
son.prototype.show=function() {

    console.info(this._name + " : " + this._age+" : "+this._height);
};
var s1 = new son("jack",12,120);

s1.show();

var p1 = new parent("father",40);
p1.show();
bubuko.com,布布扣

 

javascript类继承,布布扣,bubuko.com

javascript类继承

原文:http://www.cnblogs.com/or2-/p/3763368.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!