Created
December 1, 2013 08:38
-
-
Save jeremija/7729929 to your computer and use it in GitHub Desktop.
Recursive object traversal
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
function traverse(data) { | |
for (var objName in data) { | |
if (!data.hasOwnProperty(objName)) { | |
continue; | |
} | |
var obj = data[objName]; | |
if (typeof obj === 'object') { | |
console.log('obj: ' + objName + ' = {}...'); | |
this.traverse(obj); | |
continue; | |
} | |
if (typeof obj === 'function') { | |
obj = obj(); | |
console.log('obj: ' + objName + '() = ' + obj); | |
continue; | |
} | |
console.log('obj: ' + objName + ' = ' + obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment