
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
有命名空间的事件监听器 - event emitter with namespace
| 参数 | 必选 | 说明 |
|---|---|---|
| eventName | 是 | 监听事件名 |
| fn | 是 | 回调函数 |
| namespace | 否 | 命名空间 |
NSEvent.on('add', (a, b) => {
console.log(a, b);
});
NSEvent.on('add', (a, b) => {
console.log(a, b, 'ns');
}, 'ns');
// 1, 2
// 1, 2, 'ns'
NSEvent.emit('add', a, b);
| 参数 | 必选 | 说明 |
|---|---|---|
| eventName | 是 | 监听事件名 |
| fn | 是 | 回调函数 |
NSEvent.once('add', (a, b) => {
console.log(a, b);
});
NSEvent.emit('add', 1, 2); // 1, 2
NSEvent.emit('add', 1, 2); // nothing
| 参数 | 必选 | 说明 |
|---|---|---|
| eventName | 是 | 监听事件名 |
| arg[1,2,3...] | 否 | 传递给回调函数的值 |
| object | 否 | { 最后一个传递对象,ns: ['ns'] } 可以指定命名空间触发事件 |
NSEvent.on('fire', () => {
console.log('fire ns');
}, 'ns');
NSEvent.on('fire', () => {
console.log('fire ns2');
}, 'ns');
NSEvent.on('fire', () => {
console.log('fire');
});
NSEvent.emit('fire'); // fire ns, fire ns2, fire
console.log("======");
NSEvent.emit('fire', 1, 2, { ns: [] }); // nothing
NSEvent.emit('fire', 1, 2, { ns: ['ns'] }); // fire ns, fire ns2
| 参数 | 必选 | 说明 |
|---|---|---|
| eventName | 是 | 监听事件名 |
| string | function | array |
| string | 指定命名空间解绑 | |
| function | 指定函数解绑 | |
| array | 通过数组指定命名空间或者函数解绑 |
const NSEvent = require('../dist/nsevent.cjs');
NSEvent.on('fire', () => {
console.log('fire ns');
}, 'ns');
NSEvent.on('fire', () => {
console.log('fire ns');
}, 'ns');
NSEvent.on('fire', () => {
console.log('fire1');
}, 'ns1');
NSEvent.emit('fire'); // fire ns, fire ns, fire1
console.log('==========');
NSEvent.off('fire', ['ns']);
NSEvent.emit('fire'); // fire1
console.log('==========');
NSEvent.off('fire', 'ns1');
NSEvent.emit('fire'); // none
FAQs
> 有命名空间的事件监听器 - event emitter with namespace
We found that nsevent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.