adding boolean coercions to the faster isType methods

This commit is contained in:
Jeremy Ashkenas
2010-01-04 10:20:46 -05:00
parent abb0f7f194
commit 75a31fffc5

View File

@@ -483,7 +483,7 @@
// Is a given value an array? // Is a given value an array?
_.isArray = function(obj) { _.isArray = function(obj) {
return obj && obj.concat && obj.unshift; return !!(obj && obj.concat && obj.unshift);
}; };
// Is a given variable an arguments object? // Is a given variable an arguments object?
@@ -493,12 +493,12 @@
// Is a given value a function? // Is a given value a function?
_.isFunction = function(obj) { _.isFunction = function(obj) {
return obj && obj.constructor && obj.call && obj.apply; return !!(obj && obj.constructor && obj.call && obj.apply);
}; };
// Is a given value a string? // Is a given value a string?
_.isString = function(obj) { _.isString = function(obj) {
return obj === '' || (obj && obj.charCodeAt && obj.substr); return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
}; };
// Is a given value a number? // Is a given value a number?
@@ -508,12 +508,12 @@
// Is a given value a date? // Is a given value a date?
_.isDate = function(obj) { _.isDate = function(obj) {
return obj && obj.getTimezoneOffset && obj.setUTCFullYear; return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
}; };
// Is the given value a regular expression? // Is the given value a regular expression?
_.isRegExp = function(obj) { _.isRegExp = function(obj) {
return obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false); return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
}; };
// Is the given value NaN -- this one is interesting. NaN != NaN, and // Is the given value NaN -- this one is interesting. NaN != NaN, and