Created
August 2, 2018 04:12
-
-
Save serweb-labs/7e392216d08b9f0dee95fd42d1cd381e to your computer and use it in GitHub Desktop.
safe get attribute
This file contains hidden or 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 getAttr(o, p, d) { | |
if (!Array.isArray(p)) { p = p.split("."); } | |
var def = (d === null) ? null : (d || false); | |
return p.reduce((xs, x) => (xs && xs[x] !== undefined) ? xs[x] : def, o) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment