Skip to content

Instantly share code, notes, and snippets.

@andreyshuster
Created December 8, 2012 20:14
Show Gist options
  • Save andreyshuster/4241732 to your computer and use it in GitHub Desktop.
Save andreyshuster/4241732 to your computer and use it in GitHub Desktop.
static counter function
var uniqueID = (function() {
var id = 0; // This is the private persistent value
// The outer function returns a nested function that has access
// to the persistent value. It is this nested function we're storing
// in the variable uniqueID above.
return function() { return id++; }; // Return and increment
})(); // Invoke the outer function after defining it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment