无为清净楼资源网 Design By www.qnjia.com
复制代码 代码如下:
<html>
<head>
<script type="text/javascript"><!--
ClassModel = //类模型,用于创建类
{
create: function()
{
return function(){this.construct.apply(this,arguments);}
}
}
Extend = function(desc, src) //模拟类继承, 将一个对象的所有成员 复制到 另一个对象中
{
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() //构造函数
{
//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(); //调用human类的speak方法
var student = ClassModel.create();
student.prototype = (new human()).extend({ //student类继承类human类
sex : function() //方法重载 (多态)
{
alert("男");
},
study : function()
{
alert("studying");
},
thinking : function()
{
alert("thinking");
}
});
var student = new student();
student.sleep(); //调用 父类(human) 的sleep方法
student.study(); //调用 student的study方法
student.thinking(); //调用 student的thinking方法
student.sex(); //结果为 男 不再是父类的 女
// --></script>
</head>
</html>
<html>
<head>
<script type="text/javascript"><!--
ClassModel = //类模型,用于创建类
{
create: function()
{
return function(){this.construct.apply(this,arguments);}
}
}
Extend = function(desc, src) //模拟类继承, 将一个对象的所有成员 复制到 另一个对象中
{
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() //构造函数
{
//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(); //调用human类的speak方法
var student = ClassModel.create();
student.prototype = (new human()).extend({ //student类继承类human类
sex : function() //方法重载 (多态)
{
alert("男");
},
study : function()
{
alert("studying");
},
thinking : function()
{
alert("thinking");
}
});
var student = new student();
student.sleep(); //调用 父类(human) 的sleep方法
student.study(); //调用 student的study方法
student.thinking(); //调用 student的thinking方法
student.sex(); //结果为 男 不再是父类的 女
// --></script>
</head>
</html>
标签:
javascript,面向对象
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年10月04日
2024年10月04日
- 潘美辰.2006-最冷的夏天(引进版)【美梦辰真】【WAV+CUE】
- 班得瑞原装进口《第十张新世纪专辑:月光水岸》1CD[APE/CUE分轨][277.2MB]
- 班得瑞原装进口《第十一张新世纪专辑:雾色山脉》1CD[APE/CUE分轨][291.6MB]
- 班得瑞原装进口《第十二张新世纪专辑:翡翠谷》1CD[APE/CUE分轨][307.9MB]
- 高卿尘.2024-情绪商店【Hahahai】【FLAC分轨】
- 王恩喆.2024-黄沙【KOOD】【FLAC分轨】
- 邓丽君.1983-漫步人生路(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 陈容森.1996-情断【上华】【WAV+CUE】
- 裘海正.1994-爱我的人和我爱的人【上华】【WAV+CUE】
- 庾澄庆.1988-错过的爱【福茂】【WAV+CUE】
- 班得瑞原装进口《第十三张新世纪专辑:旭日之丘》1CD[APE/CUE分轨][329.6MB]
- 纯音入心系列纯音乐《古筝|佛蕴|境法禅心意法自然》1CD[MP3][350MB]
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[320K/MP3][203.44MB]
- 群星.1981-名曲65(2014环球复黑王·百代篇)【EMI百代】【WAV+CUE】
- 陈淑桦.1990-娃娃的故事【柯达】【WAV+CUE】