This paper analyzes the monitoring and triggering of NODEJS events. Share to everyone for your reference. The specific analysis is as follows:
About Nodejs event-driven, read the "Nodejs" or did not understand (may write a bit deep, or their own understanding is not good enough), today in the Turing community to see a Nodejs event on the monitoring and triggering, because given the example of more people, it is easy to understand, Therefore, it is also understood that the Nodejs event-driven.
The following is a reference to the Turing Community article (address: http://www.ituring.com.cn/article/177478)
First, take a look at the Nodejs event module:
Most of the modules in the Node.js are inherited from the event module. The event module (Events.eventemitter) is an implementation class for a simple incident listener pattern. Its object has the addlistener,on,once,removelistener,removealllisteners,emit and so on the basic event listener pattern realization method.
First look at an example:
var events = require ("events");
var emitter = new events. An object
//Listener event Some_event
emitter.on ("Some_event", function () {
console.log ("Eventemitter") that created the event listener. Event Trigger, call this callback function ");
settimeout (function () {
emitter.emit ("some_event"); Triggering event some_event
},3000);
Seeing this example reminds me of jquery's Custom events:
To bind the element Hello event
element.on ("Hello", function () {
alert ("Hello world!");
});
Trigger Hello event
element.trigger ("Hello");
Such a comparison makes it easy to understand the monitoring and triggering of NODEJS events. Emit is equivalent to the trigger trigger event in JQuery.
I hope this article will help you with the NODEJS program design.