<div class="codetitle"> <span><a style="CURSOR: pointer" data="18783" class="copybut" id="copybut18783" onclick="doCopy('code18783')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code18783"> <br><script type="text/javascript"> <BR>function Base(){} //根抽象类 <BR>Base.toBase=function(){ //将一个对象转化成Base类的实例的方法 <BR>return new Base(); <BR>} <BR>Base.inherit=function(parent){ //用于继承Base类的实例的方法 <BR>var F=function(){} <BR>F.prototype=parent; <BR>return new F; <BR>} <BR>Base.prototype.extend = function(prop){ //扩展根抽象类Base的extend方法 <BR>for (var o in prop) { <BR>this[o] = prop[o]; <BR>} <BR>} <BR>Base.prototype.method = function(name, fn){ //扩展根抽象类Base的method方法 <BR>this[name] = fn; <BR>return this; <BR>} <BR>var o=new Base(); //创建一个Base实例 <BR>o.method("show",function(){ //给对象o添加show方法 <BR>alert("show function"); <BR>}); <BR>o.extend({ //在给对象o添加name属性和say函数 <BR>name:"shupersha", <BR>say:function(){ <BR>alert("say function") <BR>} <BR>}); <BR>var t=Base.inherit(o); //继承o对象的属性和方法 <BR>t.show(); <BR>t.say(); <BR></script> <br> </div>