Created
April 18, 2013 00:01
-
-
Save lukelex/5408788 to your computer and use it in GitHub Desktop.
Instantiate a coffeescript object based on a JSON
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
| 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