Underscore library comes with the uniqueId() function that generates globally unique IDs to use in code. But it was not enough for my Backbone models as I needed the IDs to be unique across invocations and users, i.e. something like UUID.
I have been using this code snippet to generate pseudo unique IDs for sometime. Since it’s a utility function and it made lots of sense to move it to Underscore itself. Here’s how I did it.
Once the above code is in place, then creating a unique ID is as simple as calling _.guid().