javascript - Backbone.View.extend - events hash -


i'm going through tutorial advises events can captured via view follows:

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

there doesn't seem documentation associated events object. has been deprecated or obsolete? or looking in wrong place: http://backbonejs.org/

from view.delegateevents

delegateevents delegateevents([events])
uses jquery's on function provide declarative callbacks dom events within view. if events hash not passed directly, uses this.events source. events written in format {"event selector": "callback"}. callback may either name of method on view, or direct function body. omitting selector causes event bound view's root element (this.el). default, delegateevents called within view's constructor you, if have simple events hash, of dom events connected, , never have call function yourself.

the events property may defined function returns events hash, make easier programmatically define events, inherit them parent views.

using delegateevents provides number of advantages on manually using jquery bind events child elements during render. attached callbacks bound view before being handed off jquery, when callbacks invoked, continues refer view object. when delegateevents run again, perhaps different events hash, callbacks removed , delegated afresh — useful views need behave differently when in different modes.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -