Created
May 5, 2011 04:04
-
-
Save meltingice/956518 to your computer and use it in GitHub Desktop.
Minimal unique ID generator written in Coffeescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniqid = (-> | |
id = 0 | |
{ get: -> id++ } | |
)() | |
uniqid.get() #= 0 | |
uniqid.get() #= 1 | |
uniqid.get() #= 2, and so on... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The CoffeeScript compiles to this: | |
var uniqid = (function() { | |
var id; | |
id = 0; | |
return { | |
get: function() { | |
return id++; | |
} | |
}; | |
})(); | |
uniqid.get() //= 0 | |
uniqid.get() //= 1 | |
uniqid.get() //= 2, and so on... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment