Skip to content

Instantly share code, notes, and snippets.

@epappas
Created June 20, 2014 09:36
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 epappas/3242dd8473037966a076 to your computer and use it in GitHub Desktop.
Save epappas/3242dd8473037966a076 to your computer and use it in GitHub Desktop.
Safely traverse through object
function safeObj(obj) {
return (function obj() {
var args = Array.prototype.slice.call(arguments, 0);
return (function __get(obj, args) {
var key = args.shift();
if(key !== undefined) return __get.call(this, obj[key] || { }, args);
return obj;
}).call(this, this, args);
}).bind(obj || {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment