Backbone.View.extend - events hash

I'm going through a tutorial which advises that events can be captured via a view as follows:

var View = Backbone.View.extend({
   el: $('#element'),
   events: {},
   render: function(){}
});

There doesn't seem to be any documentation associated with this events object. Has it been deprecated or is it obsolete? Or am I just looking in the wrong place: http://backbonejs.org/

Answers


From View.delegateEvents

delegateEvents delegateEvents([events]) Uses jQuery's on function to provide declarative callbacks for DOM events within a view. If an events hash is not passed directly, uses this.events as the source. Events are written in the format {"event selector": "callback"}. The callback may be either the name of a method on the view, or a direct function body. Omitting the selector causes the event to be bound to the view's root element (this.el). By default, delegateEvents is called within the View's constructor for you, so if you have a simple events hash, all of your DOM events will always already be connected, and you will never have to call this function yourself.

The events property may also be defined as a function that returns an events hash, to make it easier to programmatically define your events, as well as inherit them from parent views.

Using delegateEvents provides a number of advantages over manually using jQuery to bind events to child elements during render. All attached callbacks are bound to the view before being handed off to jQuery, so when the callbacks are invoked, this continues to refer to the view object. When delegateEvents is run again, perhaps with a different events hash, all callbacks are removed and delegated afresh — useful for views which need to behave differently when in different modes.


Need Your Help

ref argument in C#

c# .net

First of all I am new to C# programming.

Options for implementing search in .Net web projects?

asp.net search search-engine

I come from a background in Ruby on Rails. Implementing search is relatively trivia using some of the excellent search plugins available to that community (i.e., Sphinx, Solr, etc.).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.