[婧???]JavaScript?㈠??瀵矽薄缂?绋?瀹?璺?
?(C)ShiShengSoft??????绔?锛?杞?杞借?鋒敞???哄?锛?http://blog.csdn.net/shishengsoft/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0019)http://auto.qq.com/ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript?㈠??瀵矽薄缂?绋?瀹?璺?lt;/title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style></head>
<body>
<script src="jsTimer.js" language="javascript"></script>
<script language="javascript">
// ************************************************************************************
// 绫葷??灏?瑁?锛?灞??с???規???浜?浠?// ************************************************************************************
// ??楣?// ************************************************************************************
function Tercel(sName,iMaxAge){
this.Age = 0;
this.MaxAge = iMaxAge;
this.Name = sName;
this.pullulate = pullulate;
this.Dead = function(){};
}
function pullulate(){
Print("??楣闆?ㄦ????..<br>");
while (this.Age<=this.MaxAge){??
?????? Print((this.Age++) + "<br>");
}
this.Dead();
}
// ************************************************************************************
// ????
// ************************************************************************************
function Hare(sName,iMaxAge){
this.MaxAge = iMaxAge;
this.Name = sName;
}
Hare.prototype.Age = 0;
Hare.prototype.pullulate = function(){
Print("?????ㄦ????..<br>");
while (this.Age<=this.MaxAge){??
?????? Print((this.Age++) + "<br>");
}
this.Dead();
}
Hare.prototype.Dead = function(){}
// ************************************************************************************
// 椴ㄩ奔
// ************************************************************************************
function Shark(sName,iMaxAge){
this.Age = 0;
this.MaxAge = iMaxAge;
this.Name = sName;
this.pullulate = function(){
?????? Print("椴ㄩ奔?ㄦ????..<br>");
?????? while (this.Age<=this.MaxAge){??
??????? Print((this.Age++) + "<br>");
?????? }
?????? this.Dead();
}
this.Dead = function(){};
}
// ************************************************************************************
// 绫葷??缁ф??// ************************************************************************************
// ?ㄧ?┿???虹被??
// ************************************************************************************
function Animal(sName){
var m_iAge, m_iMaxAge;
var m_DeadFunc, m_pullulateFunc;
this.Age = 0;
this.MaxAge = 0;
this.Name = sName;
??
this.Create = function(){
?????? m_iAge = this.Age;
?????? m_iMaxAge = this.MaxAge;
??
?????? m_DeadFunc = this.Dead;
?????? m_pullulateFunc = this.pullulate;
?????? MyTimer.setEnable(true);
?????? Print(this.Name + "璇???.<br>");
}
this.Dead = function(){};
this.pullulate = function(){};
var MyTimer = new jsTimer(100);
MyTimer.TimerEvent = function(){
?????? if ((++m_iAge) > m_iMaxAge){
??????? MyTimer.setEnable(false);
??????? m_DeadFunc();?????????????? //姝諱骸浜?浠??????? }
?????? else{
??????? m_pullulateFunc(m_iAge);//???誇?浠??????? }
}
}
// ************************************************************************************
// 椴擱奔
// ************************************************************************************
function Whale(sName,iMaxAge){
this.Inherit = Animal;
this.Inherit();
delete this.Inherit;
//Animal.call(this);
this.Name = sName;
this.MaxAge = iMaxAge;
this.Swim = function(){
?????? Print(this.Name + "?ㄦ搗??娓稿??<br>");
}
}
// ************************************************************************************
// 澶╅?
// ************************************************************************************
function Swan(sName,iMaxAge){
//Animal.call(this);
this.Name = sName;
this.MaxAge = iMaxAge;
this.Fly = function(){
?????? Print(this.Name + "?ㄥぉ绌洪?缈?.<br>");
}
}
Swan.prototype = new Animal();
// ************************************************************************************
// 澶???缁ф??// ************************************************************************************
function Roc(sName,iMaxAge){
Animal.call(this);
??
Whale.call(this);
Swan.call(this);
this.Name = sName;
this.MaxAge = iMaxAge;
}
?
// ************************************************************************************
</script>
<p>绫葷??灏?瑁?</p>
<p>
?????? <input name="btnTercel" type="button" id="btnTercel" value="??楣? />
?????? 40
?????? <input name="btnHare" type="button" id="btnHare" value="????" />
?????? 8
?????? <input name="btnShark" type="button" id="btnShark" value="椴ㄩ奔" />
?????? 70</p>
<p>缁ф?垮??澶???</p>
<p>
?????? <input name="btnAnimal" type="button" id="btnAnimal" value="?ㄧ??>
?????? <input name="btnWhale" type="button" id="btnWhale" value="椴擱奔" />
?????? <input name="btnSwan" type="button" id="btnSwan" value="澶╅?" />
</p>
<p>澶???缁ф??</p>
<p>椴擱奔+澶╅?=椴查?
?????? <input name="btnRoc" type="button" id="btnRoc" value="椴查?" />
</p>
<div id="Pad" style="overflow-y:scroll;font-size:12px; padding:10px 10px 10px; width:320px; height:240px; border:2px;
display:block; color:#FFFFFF; background-color:#000000"> </div>
<script type="text/javascript" language="javascript">
// ************************************************************************************
function Print(sText){
Pad.innerHTML+=sText;
}
function Clear(){
Pad.innerHTML="";
}
// ************************************************************************************
function btnTercel::onclick(){
Clear();
var MyTercel = new Tercel("??楣?,40);
MyTercel.Dead = function(){
?????? Print(MyTercel.Name + "???界???.<br>");
}
MyTercel.pullulate();
}
function btnHare::onclick(){
Clear();
var MyHare = new Hare("????",8);
MyHare.Dead = function (){
?????? Print(MyHare.Name + "???界???.<br>");
}
MyHare.pullulate();
}
function btnShark::onclick(){
Clear();
var MyShark = new Shark("椴ㄩ奔",70);
MyShark.Dead = SharkDead;
MyShark.pullulate();
}
function SharkDead(){
Print("Shark???界???.<br>");
}
// ************************************************************************************
function btnAnimal::OnClick(){
Clear();
var MyAnimal = new Animal("?ㄧ??);
MyAnimal.Dead = function(){
?????? Print(MyAnimal.Name + "???界???.<br>");
}
MyAnimal.pullulate = function(){
?????? Print("娲誨??<br>");
}
MyAnimal.Create();
}
function btnWhale::onclick(){
Clear();
var MyWhale = new Whale("椴擱奔",10);
MyWhale.Dead = function(){
?????? Print(MyWhale.Name + "???界???.<br>");
}
MyWhale.pullulate = function(){
?????? MyWhale.Swim();
}
MyWhale.Create();
}
function btnSwan::onclick(){
Clear();
var MySwan = new Swan("澶╅?",10);
MySwan.Dead = function(){
?????? Print(MySwan.Name + "???界???.<br>");
}
MySwan.pullulate = function(){
?????? MySwan.Fly();
}
MySwan.Create();
}
// ************************************************************************************
var iRnd;
function btnRoc::onclick(){
Clear();
var MyRoc = new Roc("椴查?",10);
MyRoc.Dead = function(){
?????? Print(MyRoc.Name + "???界???.<br>");
}
MyRoc.pullulate = function(){
?????? if (iRnd=!iRnd)
??????? MyRoc.Fly()
?????? else
??????? MyRoc.Swim();
}
MyRoc.Create();
}
</script>
</body>
</html>
?