Skip to content

Instantly share code, notes, and snippets.

@istarkov

istarkov/objectPathGet.js

Last active Jan 12, 2017
Embed
What would you like to do?
// no string get
const get = (fn, def) => {
try {
return fn();
} catch (e) {
return def;
}
};
// usage example
const a = { x: { y: 1 } };
const r0 = get(() => a.x.w.z, 101);
const r1 = get(() => a.x.y)
console.log(r0, r1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment