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

JavaScript 事件對象的實(shí)現(xiàn)

 更新時(shí)間:2009年07月13日 00:38:27   作者:  
前我寫過一篇關(guān)于JavaScript如何實(shí)現(xiàn)面向?qū)ο缶幊痰奈恼隆=裉?,我寫這篇文章跟大家討論一下,如何實(shí)現(xiàn)事件。
比如,我們定義了一個(gè)Classroom對象,這里我們定一個(gè)事件,當(dāng)教室里的人增加超60人時(shí)就觸發(fā)一個(gè)事件onFull;具體定義如下:
復(fù)制代碼 代碼如下:

var Classroom=function()
{
this.numberOfPeople=0;
this.onFull=null;
this.peopleEnter=function(number)
{
this.numberOfPeople+=number;
if(this.numberOfPeople>60&&this.onFull!=null)
{
this.onFull(this.numberOfPeople);
}
}
}
function show1(number)
{
alert("教室里有"+number+"人");
}
function show2(number)
{
alert("教室里超出了"+(number-60)+"人");
}
var classroom1=new Classroom();
classroom1.onFull=show1;
classroom1.peopleEnter(30);
classroom1.peopleEnter(32);
classroom1.onFull=show2;
classroom1.peopleEnter(34);

相關(guān)文章

最新評論