npm.io
1.2.0 • Published 10 years ago

ainojs-events

Licence
MIT
Version
1.2.0
Deps
0
Vulns
0
Weekly
0
Stars
1

Events

Simple event interface, suitable for mixin.

Example:

var GreatStuff = function() {
  // Apply the mixin
  Events.mixin(this)
}

GreatStuff.prototype.whatever = function() {
  this.trigger('whatever', { foo: 'bar' })
}

// [...]

var stuff = new GreatStuff()
stuff.on('whatever', function(e) {
  console.log(e.foo) // "bar"
})
stuff.whatever()

Now your class will implement a simple event interface.

Methods:

on(type, callback)
off(type[, callback])
trigger(type[, params])
once(type, callback)