Skip to content
This repository
Browse code

Removed EventEmitter.call(this) remove events chapter

No longer needed as emit() etc will check if this._events is
an object, if not it will be created
  • Loading branch information...
commit 4e5125ad0d00b744153e7c663f84d3023430a924 1 parent 56b4fd5
TJ Holowaychuk authored

Showing 2 changed files with 1 addition and 3 deletions. Show diff stats Hide diff stats

  1. +1 2  chapters/events.md
  2. +0 1  src/events/subclass.js
3  chapters/events.md
Source Rendered
@@ -22,13 +22,12 @@ Typically an object inherits from _EventEmitter_, however our small example belo
22 22
23 23 A perhaps more practical use of `EventEmitter`, and commonly used throughout node is to inherit from it. This means we can leave `EventEmitter`'s prototype untouched, while utilizing its api for our own means of world domination!
24 24
25   -To do so we begin by defining the `Dog` constructor, which of course will bark from time to time, also known as an _event_. Our `Dog` constructor accepts a `name`, followed by `EventEmitter.call(this)`, which invokes the `EventEmitter` function in context to the given argument. Doing this is essentially the same as a "super" or "parent" call in languages that support classes. This is a crucial step, as it allows `EventEmitter` to set up the `_events` property which it utilizes internally to manage callbacks.
  25 +To do so we begin by defining the `Dog` constructor, which of course will bark from time to time, also known as an _event_.
26 26
27 27 var EventEmitter = require('events').EventEmitter;
28 28
29 29 function Dog(name) {
30 30 this.name = name;
31   - EventEmitter.call(this);
32 31 }
33 32
34 33 Here we inherit from `EventEmitter`, so that we may use the methods provided such as `EventEmitter#on()` and `EventEmitter#emit()`. If the `__proto__` property is throwing you off, no worries! we will be touching on this later.
1  src/events/subclass.js
@@ -7,7 +7,6 @@ var EventEmitter = require('events').EventEmitter;
7 7
8 8 function Dog(name) {
9 9 this.name = name;
10   - EventEmitter.call(this);
11 10 }
12 11
13 12 Dog.prototype.__proto__ = EventEmitter.prototype;

0 comments on commit 4e5125a

Please sign in to comment.
Something went wrong with that request. Please try again.