Skip to content

Instantly share code, notes, and snippets.

@turbobabr
Last active Nov 22, 2016
Embed
What would you like to do?
Underscore.js isDefined mixin
// Underscore.js isDefined mixin
// Returns true if value is defined.
_.mixin({
isDefined: function(reference) {
return !_.isUndefined(reference);
}
});
/* Example:
var obj = {
definedProperty: 10
};
_.isDefined(obj.definedProperty);
=> true
_.isDefined(obj.aBunchOfCrazyMonkeysProperty);
=> false
*/
@turbobabr
Copy link
Author

turbobabr commented Apr 20, 2014

I wrote this function because I personally hate the if(!_.isUndefined(....)) {} expression. I believe that isDefined() is more clear for a reader. Have no idea why it's missing in Underscore framework itself. Inspired by angular.isDefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment