New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bind multiple event-callback pairs in one "Backbone.Events.on" call #1456
Conversation
…ll (jQuery 1.7 style)
Great stuff man! |
I think this is a great syntactic sugar... |
This is great! It follows the style of other backbone methods that provide similar, flexible parameters. |
// First argument is a map of event names => handlers | ||
// Second argument is a context object | ||
context = callback; | ||
var $this = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this $this
was for scope referencing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. This variable is redundant - I removed it in the next commit. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pshhhhhh
Sent from my Android, please excuse any typos or mistakes.
On Jul 24, 2012 1:27 PM, "Gur Dotan" <
reply@reply.github.com>
wrote:
return this;
while (event = events.shift()) {
list = calls[event] || (calls[event] = []);
list.push(callback, context);
}
return this;
}, this);
if (_.isObject(events)) {
// First argument is a map of event names => handlers
// Second argument is a context object
context = callback;
var $this = this;
Good catch. This variable is redundant - I removed it in the next commit.
Thanks!
Reply to this email directly or view it on GitHub:
https://github.com/documentcloud/backbone/pull/1456/files#r1223619
Good idea. I've pushed a different implementation. Let me know if I'm missing anything. |
👍 Awesome! |
Nice one |
Sweet implementation, hits the spot. Thanks! |
Great stuff dude! |
Instead of issuing lots of
.on
calls with different arguments, this change allows to pass a map of {event strings : callbacks} which will all be bound to the caller. A second context argument can be passed to determinethis
for all callbacks.So instead of this:
We can do this:
It becomes especially handy if you're binding lots of functions. This style is influenced by jQuery 1.7's new
.on
API.