var myFunc = function(msg, opt1, opt2) {
opt1 = _.default(opt1, ' more');
opt2 = _.default(opt2, ' and even more');
alert(msg+opt1+opt2);
}
Last active
February 21, 2016 04:46
-
-
Save danrichards/8df22221d67ffb64954f to your computer and use it in GitHub Desktop.
_.default(value, default_val) Provide a default value if param is undefined or null.
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
/** | |
* Use default vlaue | |
*/ | |
_.mixin({ | |
default: function(value, default_val) { | |
if (value === null && typeof value === "object") { | |
return default_val; | |
} | |
return _.isUndefined(value) || _.isNull(value) ? default_val : value; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment