Home > Web Front-end > JS Tutorial > Implementation of JavaScript event object_javascript skills

Implementation of JavaScript event object_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:50:12
Original
1456 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:
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template