Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created September 29, 2011 19:10
Show Gist options
  • Save ryanflorence/1251639 to your computer and use it in GitHub Desktop.
Save ryanflorence/1251639 to your computer and use it in GitHub Desktop.
CoffeeScript Immediately Invoked Function Expressions
increment = do ->
x = 0
->
x++
var increment = (function (){
var x = 0;
return function (){
return x++;
}
}());
@iammerrick
Copy link

If this had a like button I would press it.

@Kilimangaro
Copy link

To add parameters IIFE
(From http://stackoverflow.com/questions/7170446/how-to-write-this-lambda-closure-in-coffeescript

do($ = jQuery) ->
   alert "jQuery plugin!"

@mindscratch
Copy link

@Kilimangaro nice! 👍

@Pontusfa
Copy link

I'm late on the like-train but still: thumbs up!

@EvidentlyCube
Copy link

Characters reduced by: 62.5%
Readability reduced by: 80%

@ericelliott
Copy link

How does this reduce readability? I think do -> reads just fine...

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