Created
November 29, 2012 19:07
-
-
Save frostney/4171169 to your computer and use it in GitHub Desktop.
jQuery-like extend in Coffeescript
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
extend = (target, objects...) -> | |
for obj in objects | |
for key, value of obj | |
target[key] = value | |
target | |
# One object | |
a = extend {}, {test: 5} | |
alert JSON.stringify(a) | |
# More than one object | |
b = extend {}, a, {test2: 8}, {test3: 12} | |
alert JSON.stringify(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment