node.js中的events.emitter.once方法使用說明
方法說明:
為指定事件注冊(cè)一個(gè) 單次 監(jiān)聽器,所以監(jiān)聽器至多只會(huì)觸發(fā)一次,觸發(fā)后立即解除該監(jiān)聽器。
語法:
emitter.once(event, listener)
接收參數(shù):
event (string) 事件類型
listener (function) 觸發(fā)事件時(shí)的回調(diào)函數(shù)
例子:
server.once('connection', function (stream) {
console.log('Ah, we have our first user!');
});
源碼:
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的使用示例
- 詳解如何模擬實(shí)現(xiàn)node中的Events模塊(通俗易懂版)
- nodejs事件的監(jiān)聽與觸發(fā)的理解分析
- Node.js中的事件驅(qū)動(dòng)編程詳解
- Nodejs中自定義事件實(shí)例
- node.js中事件觸發(fā)器events的使用方法實(shí)例分析
相關(guān)文章
express項(xiàng)目文件目錄說明以及功能描述詳解
這篇文章主要給大家介紹了關(guān)于express項(xiàng)目文件目錄說明以及功能描述的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04在Node.js中發(fā)出HTTP請(qǐng)求的 5 種方法
學(xué)習(xí)如何在 Node.js 中發(fā)出 HTTP 請(qǐng)求可能會(huì)讓人感到不知所措,因?yàn)橛袛?shù)十個(gè)可用的庫,每個(gè)解決方案都聲稱比上一個(gè)更高效,在這篇文章中,我們將探討在 Node.js 中發(fā)出 HTTP 請(qǐng)求的五種最流行的方法,并為每種方法提供說明,需要的朋友可以參考下2023-11-11kafka調(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的解決方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-09-09Node.js 多線程實(shí)戰(zhàn)小結(jié)
在?Node.js?的世界中,多線程技術(shù)一直是一個(gè)受到廣泛關(guān)注的領(lǐng)域,本文主要介紹了Node.js 多線程實(shí)戰(zhàn)小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01node.js中的http.response.writeHead方法使用說明
這篇文章主要介紹了node.js中的http.response.writeHead方法使用說明,本文介紹了http.response.writeHead的方法說明、語法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12