Permalink
Browse files

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...
1 parent 56b4fd5 commit 4e5125ad0d00b744153e7c663f84d3023430a924 @tj tj committed Sep 20, 2010
Showing with 1 addition and 3 deletions.
  1. +1 −2 chapters/events.md
  2. +0 −1 src/events/subclass.js
View
@@ -22,13 +22,12 @@ Typically an object inherits from _EventEmitter_, however our small example belo
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!
-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.
+To do so we begin by defining the `Dog` constructor, which of course will bark from time to time, also known as an _event_.
var EventEmitter = require('events').EventEmitter;
function Dog(name) {
this.name = name;
- EventEmitter.call(this);
}
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.
@@ -7,7 +7,6 @@ var EventEmitter = require('events').EventEmitter;
function Dog(name) {
this.name = name;
- EventEmitter.call(this);
}
Dog.prototype.__proto__ = EventEmitter.prototype;

0 comments on commit 4e5125a

Please sign in to comment.