日期:2014-05-16 浏览次数:20404 次
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);?