Class = function(){ var subClass = function(){}; var superClass = arguments[0]; if(typeof(superClass) === "function"){ subClass = function(){ if(this.initialize){ this.initialize.call(this , arguments); } }; subClass.prototype = new superClass(); subClass.prototype.constructor = subClass; } subClass.prototype.extend = function(extendsObj){ for(var m in extendsObj){ this[m] = extendsObj[m]; } }; return subClass; }; SuperClass = Class(); SuperClass.prototype.extend({ a : 'superClass field a', b : function(){ return "superClass method b"; }, c : 's' }); SubClass = Class(SuperClass); SubClass.prototype.extend({ a : 'subClass field a', b : function(){ return "subClass method b"; } }); var s = new SubClass(); alert(s.a); alert(s.b()); alert(s.c);
js基于对象冒充和原型方式实现继承关系
最新推荐文章于 2022-10-25 19:58:06 发布