jashkenas/coffee-script — Issue #2045: Changing variable name passed to closure via `do` construct
Author: meltingice
Created: 2012-01-16 05:20:57+00:00
State: open

One common usage pattern that doesn't seem possible with Coffeescript's syntax is to rename variables passed into a closure. The most popular example I can think of is:

``` js
(function ($) {
// code guaranteed $ variable
})(jQuery);
```

Using the closure operator `do`, variables passed into the closure cannot be renamed. Of course, you can manually create the closure doing:

``` coffeescript
(($) ->

)(jQuery)
```

but this syntax is not as pretty as it could be. Just a suggestion, thanks!