色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript 面向?qū)ο笏枷?附源碼

復(fù)制代碼 代碼如下:
<html>
<head>
<script type="text/Javascript"><!--
ClassModel = //類模型,用于創(chuàng)建類
{
create: function()
{
return function(){this.construct.apply(this,arguments);}
}
}
Extend = function(desc, src) //模擬類繼承, 將一個對象的所有成員 復(fù)制到 另一個對象中
{
for(var c in src)
{
desc[c] = src[c];
}
return desc;
}
Object.prototype.extend = function(src)
{
return Extend.apply(this, [this, src]);
}
var human = ClassModel.create();
human.prototype =
{
construct : function() //構(gòu)造函數(shù)
{
//alert("construct method");
//alert(this.speak() + "," + this.sleep());
},
speak : function()
{
alert("speak");
},
sleep : function()
{
alert("sleep");
},
sex : function()
{
alert("女");
}
}
var h = new human();
h.speak(); //調(diào)用human類的speak方法
var student = ClassModel.create();
student.prototype = (new human()).extend({ //student類繼承類human類
sex : function() //方法重載 (多態(tài))
{
alert("男");
},
study : function()
{
alert("studying");
},
thinking : function()
{
alert("thinking");
}


});
var student = new student();
student.sleep(); //調(diào)用 父類(human) 的sleep方法
student.study(); //調(diào)用 student的study方法
student.thinking(); //調(diào)用 student的thinking方法
student.sex(); //結(jié)果為 男 不再是父類的 女

// --></script>
</head>
</html>

JavaScript技術(shù)javascript 面向?qū)ο笏枷?附源碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 油尖旺区| 尉犁县| 辉南县| 锡林浩特市| 北宁市| 城市| 郸城县| 始兴县| 惠水县| 博白县| 永德县| 柳江县| 隆回县| 洪泽县| 静安区| 历史| 霍邱县| 宣威市| 刚察县| 襄樊市| 日土县| 尼玛县| 兴安盟| 应城市| 年辖:市辖区| 若羌县| 高雄市| 陆良县| 汶上县| 太仆寺旗| 靖西县| 喀喇沁旗| 玉门市| 普安县| 罗田县| 曲麻莱县| 武陟县| 香河县| 夹江县| 灵寿县| 通州市|