Skip to content

Instantly share code, notes, and snippets.

@matthewhudson
Created June 11, 2013 20:36
Show Gist options
  • Save matthewhudson/5760422 to your computer and use it in GitHub Desktop.
Save matthewhudson/5760422 to your computer and use it in GitHub Desktop.
Generate GUID-like GUIDs w/ CoffeeScript - adapted from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
class GUID
s4: ->
Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)
create: () ->
"#{@s4()}#{@s4()}-#{@s4()}-#{@s4()}-#{@s4()}-#{@s4()}#{@s4()}#{@s4()}"
guid = new GUID
console.log guid.create()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment