Skip to content

Instantly share code, notes, and snippets.

@meltingice
Created May 5, 2011 04:04
Show Gist options
  • Save meltingice/956518 to your computer and use it in GitHub Desktop.
Save meltingice/956518 to your computer and use it in GitHub Desktop.
Minimal unique ID generator written in Coffeescript
uniqid = (->
id = 0
{ get: -> id++ }
)()
uniqid.get() #= 0
uniqid.get() #= 1
uniqid.get() #= 2, and so on...
// 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