Skip to content

Instantly share code, notes, and snippets.

@abm0
Created July 10, 2015 12:15
Show Gist options
  • Save abm0/0d330e788d3faabaa922 to your computer and use it in GitHub Desktop.
Save abm0/0d330e788d3faabaa922 to your computer and use it in GitHub Desktop.
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