@@ -444,19 +444,18 @@ the event loop to proceed, it must hit the **poll** phase, which means
444444there is a non-zero chance that a connection could have been received
445445allowing the connection event to be fired before the listening event.
446446
447- Another example is running a function constructor that was to, say,
448- inherit from ` EventEmitter ` and it wanted to call an event within the
449- constructor:
447+ Another example is inheriting from ` EventEmitter ` and emitting an
448+ event from within the constructor:
450449
451450``` js
452451const EventEmitter = require (' events' );
453- const util = require (' util' );
454452
455- function MyEmitter () {
456- EventEmitter .call (this );
457- this .emit (' event' );
453+ class MyEmitter extends EventEmitter {
454+ constructor () {
455+ super ();
456+ this .emit (' event' );
457+ }
458458}
459- util .inherits (MyEmitter, EventEmitter);
460459
461460const myEmitter = new MyEmitter ();
462461myEmitter .on (' event' , () => {
@@ -472,17 +471,17 @@ after the constructor has finished, which provides the expected results:
472471
473472``` js
474473const EventEmitter = require (' events' );
475- const util = require (' util' );
476474
477- function MyEmitter () {
478- EventEmitter .call (this );
475+ class MyEmitter extends EventEmitter {
476+ constructor () {
477+ super ();
479478
480- // use nextTick to emit the event once a handler is assigned
481- process .nextTick (() => {
482- this .emit (' event' );
483- });
479+ // use nextTick to emit the event once a handler is assigned
480+ process .nextTick (() => {
481+ this .emit (' event' );
482+ });
483+ }
484484}
485- util .inherits (MyEmitter, EventEmitter);
486485
487486const myEmitter = new MyEmitter ();
488487myEmitter .on (' event' , () => {
0 commit comments