emitter-component
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -5,4 +5,4 @@ { | ||
"keywords": ["emitter", "events"], | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"scripts": ["index.js"] | ||
} |
0.0.6 / 2012-10-08 | ||
================== | ||
* add `this._callbacks` initialization to prevent funky gotcha | ||
0.0.5 / 2012-09-07 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -16,3 +16,2 @@ | ||
if (obj) return mixin(obj); | ||
this._callbacks = {}; | ||
}; | ||
@@ -29,3 +28,2 @@ | ||
function mixin(obj) { | ||
obj._callbacks = {}; | ||
for (var key in Emitter.prototype) { | ||
@@ -47,2 +45,3 @@ obj[key] = Emitter.prototype[key]; | ||
Emitter.prototype.on = function(event, fn){ | ||
this._callbacks = this._callbacks || {}; | ||
(this._callbacks[event] = this._callbacks[event] || []) | ||
@@ -65,2 +64,3 @@ .push(fn); | ||
var self = this; | ||
this._callbacks = this._callbacks || {}; | ||
@@ -88,2 +88,3 @@ function on() { | ||
Emitter.prototype.off = function(event, fn){ | ||
this._callbacks = this._callbacks || {}; | ||
var callbacks = this._callbacks[event]; | ||
@@ -113,2 +114,3 @@ if (!callbacks) return this; | ||
Emitter.prototype.emit = function(event){ | ||
this._callbacks = this._callbacks || {}; | ||
var args = [].slice.call(arguments, 1) | ||
@@ -136,2 +138,3 @@ , callbacks = this._callbacks[event]; | ||
Emitter.prototype.listeners = function(event){ | ||
this._callbacks = this._callbacks || {}; | ||
return this._callbacks[event] || []; | ||
@@ -138,0 +141,0 @@ }; |
{ | ||
"name": "emitter-component", | ||
"description": "Event emitter", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"devDependencies": { | ||
@@ -6,0 +6,0 @@ "mocha": "*", |
@@ -17,7 +17,26 @@ # Emitter | ||
a "plain" object may become an emitter, or you may | ||
extend an existing prototype: | ||
extend an existing prototype. | ||
As an `Emitter` instance: | ||
```js | ||
var obj = {}; | ||
Emitter(obj); | ||
var Emitter = require('emitter'); | ||
var emitter = new Emitter; | ||
emitter.emit('something'); | ||
``` | ||
As a mixin: | ||
```js | ||
var Emitter = require('emitter'); | ||
var user = { name: 'tobi' }; | ||
Emitter(user); | ||
user.emit('im a user'); | ||
``` | ||
As a prototype mixin: | ||
```js | ||
var Emitter = require('emitter'); | ||
Emitter(User.prototype); | ||
@@ -24,0 +43,0 @@ ``` |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
8723
266
69
0