Skip to content
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

Added "one" method to all classes inheriting from Backbone.Event. #2

Merged
merged 3 commits into from
Dec 22, 2011

Conversation

toots
Copy link
Contributor

@toots toots commented Dec 22, 2011

No description provided.

one: (ev, callback, context) ->
self = this

fn = ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason all the cool kids use .apply, but in this case I think it's the same as this which is much easier to read:

this.unbind ev, fn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that, when fn is executed, its context may have changed. For instance, in jQuery, the callback is executed within the calling element's context. Thus, by using apply here, we make sure that we call unbind and bind with the correct context..

@toots toots merged this pull request into master Dec 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants