Created
July 7, 2017 04:26
-
-
Save akihiro/3daec38b24fdb09c47cd38acdbf915a7 to your computer and use it in GitHub Desktop.
default value on javascirpt
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 defvalue(fn, v) { | |
let ret; | |
try{ | |
ret = fn(); | |
}catch(e){ | |
ret = v; | |
} | |
if(ret === undefine){ | |
ret = v; | |
} | |
return v; | |
} | |
// suppress TypeError: created_at of undefined is not defined | |
let date = defvalue(()=>res.body.foo.created_at, null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment