Last active
January 12, 2017 02:26
-
-
Save istarkov/0ba94abff98db07c19efdc88ebd350a2 to your computer and use it in GitHub Desktop.
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
// 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