Skip to content

Instantly share code, notes, and snippets.

@lushijie
Last active February 18, 2016 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lushijie/947e5a2a016e4220bea6 to your computer and use it in GitHub Desktop.
Save lushijie/947e5a2a016e4220bea6 to your computer and use it in GitHub Desktop.
判断值是否存在&&是否为真
//undefined 与 null 返回false,其他返回true
function existy(x) {
return x != null;
}
function truthy(x) {
return (x !== false) && existy(x);
}
function doWhen(condtion, action) {
if (truthy(condition)) {
action();
} else {
return undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment