Created
June 20, 2014 09:36
-
-
Save epappas/3242dd8473037966a076 to your computer and use it in GitHub Desktop.
Safely traverse through object
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 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