Skip to content

Instantly share code, notes, and snippets.

@lukelex
Created April 18, 2013 00:01
Show Gist options
  • Select an option

  • Save lukelex/5408788 to your computer and use it in GitHub Desktop.

Select an option

Save lukelex/5408788 to your computer and use it in GitHub Desktop.
Instantiate a coffeescript object based on a JSON
class JsonBasedClass
constructor: (json) ->
for k,v of json
if k.indexOf '$'
key = @toCamel k
@[key] = v
@["$#{k}"] = v
toCamel: (field) ->
field.replace /(\_[a-z])/g, ($1) ->
$1.toUpperCase().replace "_", ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment