node.js中的events.emitter.removeAllListeners方法使用說明
更新時間:2014年12月10日 09:35:12 投稿:junjie
這篇文章主要介紹了node.js中的events.emitter.removeAllListeners方法使用說明,本文介紹了events.emitter.removeAllListeners 的方法說明、語法、接收參數(shù)、使用實例和實現(xiàn)源碼,需要的朋友可以參考下
方法說明:
移除所有監(jiān)聽器,如果指定event,則將移除指定事件的所有監(jiān)聽器。
語法:
復制代碼 代碼如下:
emitter.removeAllListeners([event])
接收參數(shù):
event 事件類型,支持多個
例子:
復制代碼 代碼如下:
//移除所有監(jiān)聽器
emitter.removeAllListeners()
//移除指定event的所有監(jiān)聽器
emitter.removeAllListeners('data')
源碼:
復制代碼 代碼如下:
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;
};
您可能感興趣的文章:
- node.js中的events.emitter.once方法使用說明
- 詳解Node.js:events事件模塊
- node.js中的events.emitter.removeListener方法使用說明
- node.js中的events.EventEmitter.listenerCount方法使用說明
- 關(guān)于Node.js的events.EventEmitter用法介紹
- node.js中的events.emitter.listeners方法使用說明
- node.js學習之事件模塊Events的使用示例
- 詳解如何模擬實現(xiàn)node中的Events模塊(通俗易懂版)
- nodejs事件的監(jiān)聽與觸發(fā)的理解分析
- Node.js中的事件驅(qū)動編程詳解
- Nodejs中自定義事件實例
- node.js中事件觸發(fā)器events的使用方法實例分析
相關(guān)文章
輕松創(chuàng)建nodejs服務器(2):nodejs服務器的構(gòu)成分析
這篇文章主要介紹了輕松創(chuàng)建nodejs服務器(2):nodejs服務器的構(gòu)成分析,本文是對第一節(jié)中簡單服務器的代碼進行分析總結(jié),需要的朋友可以參考下2014-12-12
node實現(xiàn)生成帶參數(shù)的小程序二維碼并保存到本地功能示例
這篇文章主要介紹了node實現(xiàn)生成帶參數(shù)的小程序二維碼并保存到本地功能,涉及nodejs模塊引用、接口調(diào)用、編碼轉(zhuǎn)換、圖片生成等相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
express中創(chuàng)建 websocket 接口及問題解答
本文主要介紹了express中創(chuàng)建 websocket 接口及問題解答,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05
在Node.js中使用Express實現(xiàn)視頻評論的列表展示和刪除功能
在現(xiàn)代Web應用中,視頻內(nèi)容和互動功能(如評論)的結(jié)合極大地增加了用戶的參與度,本文將通過一個具體的例子,展示如何在Node.js環(huán)境中使用Express框架來實現(xiàn)視頻評論的列表展示和刪除功能,需要的朋友可以參考下2024-04-04

