Skip to content

@@method => method.bind(this) #3634

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

Closed
brianmhunt opened this issue Sep 12, 2014 · 2 comments
Closed

@@method => method.bind(this) #3634

brianmhunt opened this issue Sep 12, 2014 · 2 comments

Comments

@brianmhunt
Copy link

Just a suggestion for a possibly handy shorthand of @@method for the equivalent of fn.bind(this) (or in CoffeeScript parlance __bind).

This is just a bit of syntactic sugar where one has a class with a number of handlers e.g. for illustration:

class Handler
   constructor: (node) ->
     $(node)
       .on('click', @@on_click)
       .on("mouseover", @@on_mouserover)

      # versus
       .on('click', @on_click.bind(@)) # ES5, or
       .on('click', _.bind(@on_click, @)  # lodash/underscore

   on_click: -> #...
   on_mouseover: -> # ...

This is not to rule out alternative syntax options, but it struck me that @@ was a. unused, b. somewhat expressive of the intention, and c. easy to remember.

Cheers.

@vendethiel
Copy link
Collaborator

This seems to be a dup for #251/#431 (and its descendants, like #3093).

(For the record, Coco and LS use @~fun)

@brianmhunt
Copy link
Author

Thanks @Nami-Doc

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

No branches or pull requests

2 participants