Created
July 10, 2015 12:15
-
-
Save abm0/0d330e788d3faabaa922 to your computer and use it in GitHub Desktop.
This file contains 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
traverse = (obj, path, callback) -> | |
i = 0 | |
do (obj) -> | |
key = path[i] | |
i++ | |
if typeof obj[key] is 'object' | |
arguments.callee obj[key] | |
else | |
callback obj, key | |
obj = | |
foo: | |
bar: 'Old value' | |
path = ['foo', 'bar'] | |
callback = (obj, key) -> | |
obj[key] = 'New value' | |
traverse obj, path, callback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment