nodejs里socket.on和socket.once的单步调试
2023-09-14 09:03:58 时间
一个网友的求助:
https://stackoverflow.com/questions/49788422/socket-on-event-gets-triggered-multiple-times
其他朋友建议他用socket.once, 而非socket.on
socket对象本身并没有on的方法:
原型链上才有:
执行on(“createKOIID”, fn)之前的监听事件函数池:
使用on注册之后:
再看once的实现:
on是一个函数,once传入的监听函数作为一个属性赋值到on上:
然后照常用on注册事件:
注册完毕。
事件触发时,首先执行on:
在on里面会先解除掉对event的注册:
第1600行会把事件处理函数从handler repository里移除掉。
最后执行对应的事件处理函数。
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- Nodejs Express 4.X 中文API 3--- Response篇
- Nodejs 使用 bcrypt 库加密和验证密码
- [Test] Easy automated testing in NodeJS with TestCafe
- [NodeJS] Use Secrets When Deploying Applications with Now
- [Tools] Using colours in a NodeJS terminal - make your output pop
- [Node.js] Identify memory leaks with nodejs-dashboard
- 用nodejs实现一个简单的聊天室
- Verdaccio介绍及安装 -- nodejs私有npm proxy registry代理
- Atitit nodejs5 nodejs6 nodejs 7.2.1 新特性attialx总结
- 使用nodejs代码在SAP C4C里创建Individual customer
- 用nodejs做一下发送邮件例子
- Nodejs学习笔记2
- 【Nodejs】回顾node中如何使用Express模块写接口_05