|
<script type="text/Javascript">
function Base(){} //根抽象類
Base.toBase=function(){ //將一個(gè)對(duì)象轉(zhuǎn)化成Base類的實(shí)例的方法
return new Base();
}
Base.inherit=function(parent){ //用于繼承Base類的實(shí)例的方法
var F=function(){}
F.prototype=parent;
return new F;
}
Base.prototype.extend = function(prop){ //擴(kuò)展根抽象類Base的extend方法
for (var o in prop) {
this[o] = prop[o];
}
}
Base.prototype.method = function(name, fn){ //擴(kuò)展根抽象類Base的method方法
this[name] = fn;
return this;
}
var o=new Base(); //創(chuàng)建一個(gè)Base實(shí)例
o.method("show",function(){ //給對(duì)象o添加show方法
alert("show function");
});
o.extend({ //在給對(duì)象o添加name屬性和say函數(shù)
name:"shupersha",
say:function(){
alert("say function")
}
});
var t=Base.inherit(o); //繼承o對(duì)象的屬性和方法
t.show();
t.say();
</script>
JavaScript技術(shù):javascript Base類 包含基本的方法,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。