Created
December 8, 2012 20:14
-
-
Save andreyshuster/4241732 to your computer and use it in GitHub Desktop.
static counter function
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
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