Beautiful JS

JavaScript that belies the common conception of beauty

Backbone events definition

Backbone.js allows you to define delegated-events for your views in a neat little hash in which you specify the event name, the selector (the context being the view itself) and a method-name to call on the view instance:

var FooView = Backbone.View.extend({

	events: {
	    "dblclick"                : "open",
	    "click .icon.doc"         : "select",
	    "contextmenu .icon.doc"   : "showMenu",
	    "click .show_notes"       : "toggleNotes",
	    "click .title .lock"      : "editAccessLevel",
	    "mouseover .title .date"  : "showTooltip"
	},

	//...

});

See the documentation for Backbone’s delegateEvents.

Posted by James on 01 Oct 2011 | linky

Subscribe or follow @Beautiful_JS! | Fork then send a pull request to contribute.

Disclaimer: Beautiful code is readable, maintainable and scalable. It's not just nice to look it.