node.js中的events.emitter.once方法使用說明
更新時間:2014年12月10日 09:48:36 投稿:junjie
這篇文章主要介紹了node.js中的events.emitter.once方法使用說明,本文介紹了events.emitter.once的方法說明、語法、接收參數(shù)、使用實例和實現(xiàn)源碼,需要的朋友可以參考下
方法說明:
為指定事件注冊一個 單次 監(jiān)聽器,所以監(jiān)聽器至多只會觸發(fā)一次,觸發(fā)后立即解除該監(jiān)聽器。
語法:
復(fù)制代碼 代碼如下:
emitter.once(event, listener)
接收參數(shù):
event (string) 事件類型
listener (function) 觸發(fā)事件時的回調(diào)函數(shù)
例子:
復(fù)制代碼 代碼如下:
server.once('connection', function (stream) {
console.log('Ah, we have our first user!');
});
源碼:
復(fù)制代碼 代碼如下:
EventEmitter.prototype.once = function(type, listener) {
if (!util.isFunction(listener))
throw TypeError('listener must be a function');
function g() {
this.removeListener(type, g);
listener.apply(this, arguments);
}
g.listener = listener;
this.on(type, g);
return this;
};
您可能感興趣的文章:
- 詳解Node.js:events事件模塊
- node.js中的events.emitter.removeListener方法使用說明
- node.js中的events.emitter.removeAllListeners方法使用說明
- node.js中的events.EventEmitter.listenerCount方法使用說明
- 關(guān)于Node.js的events.EventEmitter用法介紹
- node.js中的events.emitter.listeners方法使用說明
- node.js學(xué)習(xí)之事件模塊Events的使用示例
- 詳解如何模擬實現(xiàn)node中的Events模塊(通俗易懂版)
- nodejs事件的監(jiān)聽與觸發(fā)的理解分析
- Node.js中的事件驅(qū)動編程詳解
- Nodejs中自定義事件實例
- node.js中事件觸發(fā)器events的使用方法實例分析
相關(guān)文章
kafka調(diào)試中遇到Connection to node -1 could not be established. Br
這篇文章主要介紹了kafka調(diào)試中遇到Connection to node -1 could not be established. Broker may not be available的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-09-09node.js中的http.response.writeHead方法使用說明
這篇文章主要介紹了node.js中的http.response.writeHead方法使用說明,本文介紹了http.response.writeHead的方法說明、語法、接收參數(shù)、使用實例和實現(xiàn)源碼,需要的朋友可以參考下2014-12-12