Home > Web Front-end > JS Tutorial > body text

Implementation of JavaScript event object_javascript skills

WBOY
Release: 2016-05-16 18:50:12
Original
1384 people have browsed it

For example, we define a Classroom object. Here we define an event. When the number of people in the classroom increases by more than 60, an event onFull is triggered; the specific definition is as follows:

Copy the code The code is as follows:

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("There are " number "people" in the classroom);
}
function show2(number)
{
alert("The classroom exceeds" (number-60) "people");
}
var classroom1=new Classroom();
classroom1.onFull=show1;
classroom1.peopleEnter(30);
classroom1.peopleEnter(32);
classroom1.onFull=show2;
classroom1.peopleEnter(34);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!