码迷,mamicode.com
首页 > 编程语言 > 详细

javascript类继承

时间:2014-06-01 17:11:29      阅读:385      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

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类继承

标签:c   style   class   blog   code   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!