Skip to content

Commit 75a31ff

Browse files
committed
adding boolean coercions to the faster isType methods
1 parent abb0f7f commit 75a31ff

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

underscore.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@
483483

484484
// Is a given value an array?
485485
_.isArray = function(obj) {
486-
return obj && obj.concat && obj.unshift;
486+
return !!(obj && obj.concat && obj.unshift);
487487
};
488488

489489
// Is a given variable an arguments object?
@@ -493,12 +493,12 @@
493493

494494
// Is a given value a function?
495495
_.isFunction = function(obj) {
496-
return obj && obj.constructor && obj.call && obj.apply;
496+
return !!(obj && obj.constructor && obj.call && obj.apply);
497497
};
498498

499499
// Is a given value a string?
500500
_.isString = function(obj) {
501-
return obj === '' || (obj && obj.charCodeAt && obj.substr);
501+
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
502502
};
503503

504504
// Is a given value a number?
@@ -508,12 +508,12 @@
508508

509509
// Is a given value a date?
510510
_.isDate = function(obj) {
511-
return obj && obj.getTimezoneOffset && obj.setUTCFullYear;
511+
return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
512512
};
513513

514514
// Is the given value a regular expression?
515515
_.isRegExp = function(obj) {
516-
return obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false);
516+
return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
517517
};
518518

519519
// Is the given value NaN -- this one is interesting. NaN != NaN, and

0 commit comments

Comments
 (0)