mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Optimize _.isBoolean, _.isNumber, and _.isString for the false case.
This commit is contained in:
26
lodash.js
26
lodash.js
@@ -2436,7 +2436,8 @@
|
||||
* // => false
|
||||
*/
|
||||
function isBoolean(value) {
|
||||
return value === true || value === false || toString.call(value) == boolClass;
|
||||
return value === true || value === false ||
|
||||
value && typeof value == 'object' && toString.call(value) == boolClass || false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2453,7 +2454,7 @@
|
||||
* // => true
|
||||
*/
|
||||
function isDate(value) {
|
||||
return value ? (typeof value == 'object' && toString.call(value) == dateClass) : false;
|
||||
return value && typeof value == 'object' && toString.call(value) == dateClass || false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2470,7 +2471,7 @@
|
||||
* // => true
|
||||
*/
|
||||
function isElement(value) {
|
||||
return value ? value.nodeType === 1 : false;
|
||||
return value && value.nodeType === 1 || false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2705,7 +2706,8 @@
|
||||
* // => true
|
||||
*/
|
||||
function isNumber(value) {
|
||||
return typeof value == 'number' || toString.call(value) == numberClass;
|
||||
return typeof value == 'number' ||
|
||||
value && typeof value == 'object' && toString.call(value) == numberClass || false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2758,7 +2760,7 @@
|
||||
* // => true
|
||||
*/
|
||||
function isRegExp(value) {
|
||||
return (value && objectTypes[typeof value]) ? toString.call(value) == regexpClass : false;
|
||||
return value && objectTypes[typeof value] && toString.call(value) == regexpClass || false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2775,7 +2777,8 @@
|
||||
* // => true
|
||||
*/
|
||||
function isString(value) {
|
||||
return typeof value == 'string' || toString.call(value) == stringClass;
|
||||
return typeof value == 'string' ||
|
||||
value && typeof value == 'object' && toString.call(value) == stringClass || false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5913,12 +5916,11 @@
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var hello = function(name) { return 'hello ' + name; };
|
||||
* hello = _.wrap(hello, function(func) {
|
||||
* return 'before, ' + func('fred') + ', after';
|
||||
* var pre= _.wrap(_.escape, function(func, text) {
|
||||
* return '<div>' + func(text) + '</div>';
|
||||
* });
|
||||
* hello();
|
||||
* // => 'before, hello fred, after'
|
||||
* pre('Fred, Wilma, & Pebbles');
|
||||
* // => '<div>Fred, Wilma, & Pebbles</div>'
|
||||
*/
|
||||
function wrap(value, wrapper) {
|
||||
if (!isFunction(wrapper)) {
|
||||
@@ -5962,7 +5964,7 @@
|
||||
* @example
|
||||
*
|
||||
* var object = { 'name': 'fred' };
|
||||
* object === _.identity(object);
|
||||
* _.identity(object) === object;
|
||||
* // => true
|
||||
*/
|
||||
function identity(value) {
|
||||
|
||||
Reference in New Issue
Block a user