javascript类继承
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();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。