Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

docs: emitter.listeners return a copy of original array rather than an array reference #9022

@StevenRoan

Description

@StevenRoan

As title, the document use the description

  • Returns an array of listeners for the specified event.

However, return an array usually indicating return an array reference, and here is different.
Maybe we can consider to modify this part of document, Thanks!

Example code

var EventEmitter = require('events').EventEmitter;
var eventEmitter = new EventEmitter();
var arrListeners = eventEmitter.listeners('test-event');
console.log(arrListeners.length);
eventEmitter.addListener('test-event', function(){
  //Do sth.
});
console.log(arrListeners.length); // log 0 because the this array reference is different with current one. 
arrListeners = eventEmitter.listeners('test-event');
console.log(arrListeners.length);

get output
0
0
1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions