欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript Base類(lèi) 包含基本的方法

 更新時(shí)間:2009年07月22日 00:13:17   作者:  
一個(gè)Base類(lèi),包含基本的方法,大家可以在這個(gè)基礎(chǔ)上拓展下功能。
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function Base(){} //根抽象類(lèi)
Base.toBase=function(){ //將一個(gè)對(duì)象轉(zhuǎn)化成Base類(lèi)的實(shí)例的方法
return new Base();
}
Base.inherit=function(parent){ //用于繼承Base類(lèi)的實(shí)例的方法
var F=function(){}
F.prototype=parent;
return new F;
}
Base.prototype.extend = function(prop){ //擴(kuò)展根抽象類(lèi)Base的extend方法
for (var o in prop) {
this[o] = prop[o];
}
}
Base.prototype.method = function(name, fn){ //擴(kuò)展根抽象類(lèi)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>

相關(guān)文章

最新評(píng)論