Skip to content

Instantly share code, notes, and snippets.

@greduan
Created May 13, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greduan/0708ea833085cd278e46 to your computer and use it in GitHub Desktop.
Save greduan/0708ea833085cd278e46 to your computer and use it in GitHub Desktop.
recursive func which goes goes through object and finds all .init() funcs and runs them
var initialiseKeys = function initialiseKeys (obj) {
var val
for (var key in obj) {
val = obj[key]
// the key isn't 'init' BUT it's an object we need to explore it
if (key !== 'init' && typeof val === 'object') {
initialiseKeys(val)
// hey the key is 'init' and its value is a function!
} else if (key === 'init' && typeof val === 'function') {
obj.init()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment