Events. emitter. removeAllListeners method in node. js

Source: Internet
Author: User

Events. emitter. removeAllListeners method in node. js

Method description:

Removes all listeners. If an event is specified, all listeners of the specified event are removed.

Syntax:

Copy codeThe Code is as follows:
Emitter. removeAllListeners ([event])

Receiving parameters:

Event type. Multiple event types are supported.

Example:

Copy codeThe Code is as follows:
// Remove all listeners
 
Emitter. removeAllListeners ()
 
// Remove all listeners of the specified event
 
Emitter. removeAllListeners ('data ')

Source code:

Copy codeThe Code is as follows:
EventEmitter. prototype. removeAllListeners = function (type ){
Var key, listeners;
If (! This. _ events)
Return this;
// Not listening for removeListener, no need to emit
If (! This. _ events. removeListener ){
If (arguments. length = 0)
This. _ events = {};
Else if (this. _ events [type])
Delete this. _ events [type];
Return this;
}
// Emit removeListener for all listeners on all events
If (arguments. length = 0 ){
For (key in this. _ events ){
If (key = 'removelistener ') continue;
This. removeAllListeners (key );
}
This. removeAllListeners ('removelistener ');
This. _ events = {};
Return this;
}
Listeners = this. _ events [type];
If (util. isFunction (listeners )){
This. removeListener (type, listeners );
} Else {
// LIFO order
While (listeners. length)
This. removeListener (type, listeners [listeners. length-1]);
}
Delete this. _ events [type];
Return this;
};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.