doc: add `added:` information for events · nodejs/node@769f63c

@@ -167,6 +167,9 @@ myEmitter.emit('error', new Error('whoops!'));

167167

```

168168169169

## Class: EventEmitter

170+

<!-- YAML

171+

added: v0.1.26

172+

-->

170173171174

The `EventEmitter` class is defined and exposed by the `events` module:

172175

@@ -178,6 +181,9 @@ All EventEmitters emit the event `'newListener'` when new listeners are

178181

added and `'removeListener'` when existing listeners are removed.

179182180183

### Event: 'newListener'

184+

<!-- YAML

185+

added: v0.1.26

186+

-->

181187182188

* `eventName` {String|Symbol} The name of the event being listened for

183189

* `listener` {Function} The event handler function

@@ -214,13 +220,20 @@ myEmitter.emit('event');

214220

```

215221216222

### Event: 'removeListener'

223+

<!-- YAML

224+

added: v0.9.3

225+

-->

217226218227

* `eventName` {String|Symbol} The event name

219228

* `listener` {Function} The event handler function

220229221230

The `'removeListener'` event is emitted *after* the `listener` is removed.

222231223232

### EventEmitter.listenerCount(emitter, eventName)

233+

<!-- YAML

234+

added: v0.9.12

235+

deprecated: v4.0.0

236+

-->

224237225238

> Stability: 0 - Deprecated: Use [`emitter.listenerCount()`][] instead.

226239

@@ -236,6 +249,9 @@ console.log(EventEmitter.listenerCount(myEmitter, 'event'));

236249

```

237250238251

### EventEmitter.defaultMaxListeners

252+

<!-- YAML

253+

added: v0.11.2

254+

-->

239255240256

By default, a maximum of `10` listeners can be registered for any single

241257

event. This limit can be changed for individual `EventEmitter` instances

@@ -263,10 +279,16 @@ emitter.once('event', () => {

263279

```

264280265281

### emitter.addListener(eventName, listener)

282+

<!-- YAML

283+

added: v0.1.26

284+

-->

266285267286

Alias for `emitter.on(eventName, listener)`.

268287269288

### emitter.emit(eventName[, arg1][, arg2][, ...])

289+

<!-- YAML

290+

added: v0.1.26

291+

-->

270292271293

Synchronously calls each of the listeners registered for the event named

272294

`eventName`, in the order they were registered, passing the supplied arguments

@@ -275,6 +297,9 @@ to each.

275297

Returns `true` if the event had listeners, `false` otherwise.

276298277299

### emitter.eventNames()

300+

<!-- YAML

301+

added: v6.0.0

302+

-->

278303279304

Returns an array listing the events for which the emitter has registered

280305

listeners. The values in the array will be strings or Symbols.

@@ -293,18 +318,27 @@ console.log(myEE.eventNames());

293318

```

294319295320

### emitter.getMaxListeners()

321+

<!-- YAML

322+

added: v1.0.0

323+

-->

296324297325

Returns the current max listener value for the `EventEmitter` which is either

298326

set by [`emitter.setMaxListeners(n)`][] or defaults to

299327

[`EventEmitter.defaultMaxListeners`][].

300328301329

### emitter.listenerCount(eventName)

330+

<!-- YAML

331+

added: v3.2.0

332+

-->

302333303334

* `eventName` {String|Symbol} The name of the event being listened for

304335305336

Returns the number of listeners listening to the event named `eventName`.

306337307338

### emitter.listeners(eventName)

339+

<!-- YAML

340+

added: v0.1.26

341+

-->

308342309343

Returns a copy of the array of listeners for the event named `eventName`.

310344

@@ -317,6 +351,9 @@ console.log(util.inspect(server.listeners('connection')));

317351

```

318352319353

### emitter.on(eventName, listener)

354+

<!-- YAML

355+

added: v0.1.101

356+

-->

320357321358

* `eventName` {String|Symbol} The name of the event.

322359

* `listener` {Function} The callback function

@@ -350,6 +387,9 @@ myEE.emit('foo');

350387

```

351388352389

### emitter.once(eventName, listener)

390+

<!-- YAML

391+

added: v0.3.0

392+

-->

353393354394

* `eventName` {String|Symbol} The name of the event.

355395

* `listener` {Function} The callback function

@@ -380,6 +420,9 @@ myEE.emit('foo');

380420

```

381421382422

### emitter.prependListener(eventName, listener)

423+

<!-- YAML

424+

added: v6.0.0

425+

-->

383426384427

* `eventName` {String|Symbol} The name of the event.

385428

* `listener` {Function} The callback function

@@ -399,6 +442,9 @@ server.prependListener('connection', (stream) => {

399442

Returns a reference to the `EventEmitter`, so that calls can be chained.

400443401444

### emitter.prependOnceListener(eventName, listener)

445+

<!-- YAML

446+

added: v6.0.0

447+

-->

402448403449

* `eventName` {String|Symbol} The name of the event.

404450

* `listener` {Function} The callback function

@@ -416,6 +462,9 @@ server.prependOnceListener('connection', (stream) => {

416462

Returns a reference to the `EventEmitter`, so that calls can be chained.

417463418464

### emitter.removeAllListeners([eventName])

465+

<!-- YAML

466+

added: v0.1.26

467+

-->

419468420469

Removes all listeners, or those of the specified `eventName`.

421470

@@ -426,6 +475,9 @@ component or module (e.g. sockets or file streams).

426475

Returns a reference to the `EventEmitter`, so that calls can be chained.

427476428477

### emitter.removeListener(eventName, listener)

478+

<!-- YAML

479+

added: v0.1.26

480+

-->

429481430482

Removes the specified `listener` from the listener array for the event named

431483

`eventName`.

@@ -490,6 +542,9 @@ the `emitter.listeners()` method will need to be recreated.

490542

Returns a reference to the `EventEmitter`, so that calls can be chained.

491543492544

### emitter.setMaxListeners(n)

545+

<!-- YAML

546+

added: v0.3.5

547+

-->

493548494549

By default EventEmitters will print a warning if more than `10` listeners are

495550

added for a particular event. This is a useful default that helps finding