listenTo - can't specify context for the callback #1946

Closed
AjaxSolutions opened this Issue Dec 14, 2012 · 5 comments

Projects

None yet

5 participants

@AjaxSolutions

Would you say context param should be added?

listenTo: function(object, events, callback) {
...

@jashkenas
Owner

Nope. The whole idea with listenTo is that the object you're calling it from is the context.

view.listenTo(model, 'change', ...)

view is the context.

@jashkenas jashkenas closed this Dec 14, 2012
@spacenick

Why not adding an optional context? It would definately speed up things for this kind of callbacks :

view.listenTo(object,'some events',this.$el.show,this.$el)

Instead of having to write manually trivial functions on the view that will just delegate to the exact same jQuery method on $el. What do you think?

@tbranyen
Collaborator

Maybe, view.listenTo(object, 'some events', _.bind(this.$el.show, this.$el)); ?

@anthonyshort

Using the same context means events can easily be removed and cleaned up when the view is destroyed. Having another context would mean this wouldn't happen and you'd need to manually clean up the events like with on

@spacenick

Yeah ok it makes more sense the way it is and @tbranyen solution is perfect, ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment