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

Feature Request: Self-Executing Anonymous Functions (with variable aliasing) #2235

Closed
sankage opened this issue Apr 3, 2012 · 8 comments
Closed
Labels

Comments

@sankage
Copy link

sankage commented Apr 3, 2012

I have been looking around to see if it already exists, but I can't find anything. I was hoping for some syntactic sugar for self-executing anonymous functions with variable aliasing.

Right now, to get this:

(function($, exports){
  /* doing random stuff here */
})(jQuery, window);

We have to do this:

( ($, exports) ->
  # doing random stuff here
)(jQuery, window)

This seems like extra work given that functions have been reduced to -> and self-executing functions to do ->

@michaelficarra
Copy link
Collaborator

We have to do this

Nope.

do ($ = jQuery, exports = window) ->
  # doing random stuff here

@jashkenas
Copy link
Owner

FYI, that code won't work.

@michaelficarra
Copy link
Collaborator

@jashkenas: what do you mean by that? It works. Compile it.

@sankage
Copy link
Author

sankage commented Apr 3, 2012

do ($ = jQuery, exports = window) ->
  #stuff

compiled is

(function($, exports) {
  if ($ == null) $ = jQuery;
  if (exports == null) exports = window;
})($, exports);

@michaelficarra
Copy link
Collaborator

Not for me...

$ coffee -v
CoffeeScript version 1.2.1-pre
$ coffee -bsp
do ($ = jQuery, exports = window) ->
  #stuff
(function($, exports) {})(jQuery, window);
$ 

@jashkenas
Copy link
Owner

Oh, lovely -- it's improved on master then, and'll go out with the next release.

@sankage
Copy link
Author

sankage commented Apr 3, 2012

Sweet!

feature request achieved! :P

@michaelficarra
Copy link
Collaborator

See #960 for this change. It's one of the earlier commits in the set of commits since the last release.

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

No branches or pull requests

3 participants