Skip to content

Basic events: 'on', 'trigger'. Intuitive _this_ treatment

Notifications You must be signed in to change notification settings

itsjoesullivan/event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#Event

Basic events, for when you want to do _.extend(obj, Backbone.Events ) but don't need Backbone. Slightly different API and less functionality than Backbone, btw!

##Usage

###Standalone:

	var events = new Events();

	events.on('knock', function() { console.log('who\'s there?'); });

	events.trigger('knock');
	// who's there?

###Inheritance:

####Traditional

	var Person = function() {
		this.on('wake',this.brushTeeth); // 'this' will be Person instance
		this.on('wake',this.brushTeeth.bind(Ralph)); // 'this' will be Ralph
	};
	Person.prototype = new Events();

####_.extend()

	var me = {};
	_.extend(me, new Events() );

##API

###Events.on(name,fn)

Adds listener to that particular event.

###Events.trigger(name,arg1,arg2,...)

Triggers a particular event by name, passing along subsequent arguments.

About

Basic events: 'on', 'trigger'. Intuitive _this_ treatment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published