Skip to content

Simple event interface, suitable for prototype mixin

Notifications You must be signed in to change notification settings

darcyadams/ainojs-events

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Events

Simple event interface, suitable for prototype mixin.

Example:

var GreatStuff = function() {}

// apply the mixin
Events.call(GreatStuff.prototype)

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)

About

Simple event interface, suitable for prototype mixin

Resources

Stars

Watchers

Forks

Packages

No packages published