app.myView = Backbone.View.extend({
events: {
'mouseenter .myitem': 'myfunction'
}
});
how do i delay this event from being created until a certain time or until I decide that i’d like to create it. right now it is created as soon as my view is loading in and the mouseevent is triggering as soon as I enter .myitem
Backbone binds view events using
delegateEvents:You can call
delegateEventswhenever you want to change the event bindings. So one way to do this would be to adjustthis.eventsand callthis.delegateEvents():The
extendcall is a good idea becauseBackbone.View.extendwill leave theeventsattached the view’s prototype so simply changingthis.events:would alter the
eventsfor all instances of the view. The advantage of this is that callingundelegateEventswill do the Right Thing and all your view events will be handled the same way.Demo: http://jsfiddle.net/ambiguous/Bd4SB/