Replace typeof checks for undefined with === checks.

This commit is contained in:
jdalton
2015-04-08 09:28:51 -07:00
parent bb06d98a43
commit 745d97ebe1

View File

@@ -301,10 +301,10 @@
var valIsReflexive = value === value, var valIsReflexive = value === value,
othIsReflexive = other === other; othIsReflexive = other === other;
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) { if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) {
return 1; return 1;
} }
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) { if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) {
return -1; return -1;
} }
} }
@@ -1724,7 +1724,7 @@
* @returns {*} Returns the value to assign to the destination object. * @returns {*} Returns the value to assign to the destination object.
*/ */
function assignDefaults(objectValue, sourceValue) { function assignDefaults(objectValue, sourceValue) {
return typeof objectValue == 'undefined' ? sourceValue : objectValue; return objectValue === undefined ? sourceValue : objectValue;
} }
/** /**
@@ -1741,7 +1741,7 @@
* @returns {*} Returns the value to assign to the destination object. * @returns {*} Returns the value to assign to the destination object.
*/ */
function assignOwnDefaults(objectValue, sourceValue, key, object) { function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key)) return (objectValue === undefined || !hasOwnProperty.call(object, key))
? sourceValue ? sourceValue
: objectValue; : objectValue;
} }
@@ -1770,7 +1770,7 @@
result = customizer(value, source[key], key, object, source); result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) || if ((result === result ? (result !== value) : (value === value)) ||
(typeof value == 'undefined' && !(key in object))) { (value === undefined && !(key in object))) {
object[key] = result; object[key] = result;
} }
} }
@@ -1841,7 +1841,7 @@
function baseCallback(func, thisArg, argCount) { function baseCallback(func, thisArg, argCount) {
var type = typeof func; var type = typeof func;
if (type == 'function') { if (type == 'function') {
return typeof thisArg == 'undefined' return thisArg === undefined
? func ? func
: bindCallback(func, thisArg, argCount); : bindCallback(func, thisArg, argCount);
} }
@@ -1851,7 +1851,7 @@
if (type == 'object') { if (type == 'object') {
return baseMatches(func); return baseMatches(func);
} }
return typeof thisArg == 'undefined' return thisArg === undefined
? property(func) ? property(func)
: baseMatchesProperty(func, thisArg); : baseMatchesProperty(func, thisArg);
} }
@@ -1875,7 +1875,7 @@
if (customizer) { if (customizer) {
result = object ? customizer(value, key, object) : customizer(value); result = object ? customizer(value, key, object) : customizer(value);
} }
if (typeof result != 'undefined') { if (result !== undefined) {
return result; return result;
} }
if (!isObject(value)) { if (!isObject(value)) {
@@ -2068,7 +2068,7 @@
if (start < 0) { if (start < 0) {
start = -start > length ? 0 : (length + start); start = -start > length ? 0 : (length + start);
} }
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) { if (end < 0) {
end += length; end += length;
} }
@@ -2266,7 +2266,7 @@
return; return;
} }
object = toObject(object); object = toObject(object);
if (typeof pathKey != 'undefined' && pathKey in object) { if (pathKey !== undefined && pathKey in object) {
path = [pathKey]; path = [pathKey];
} }
var index = -1, var index = -1,
@@ -2419,10 +2419,10 @@
srcValue = values[index]; srcValue = values[index];
if (noCustomizer && strictCompareFlags[index]) { if (noCustomizer && strictCompareFlags[index]) {
var result = typeof objValue != 'undefined' || (key in object); var result = objValue !== undefined || (key in object);
} else { } else {
result = customizer ? customizer(objValue, srcValue, key) : undefined; result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (typeof result == 'undefined') { if (result === undefined) {
result = baseIsEqual(srcValue, objValue, customizer, true); result = baseIsEqual(srcValue, objValue, customizer, true);
} }
} }
@@ -2474,7 +2474,7 @@
return false; return false;
} }
object = toObject(object); object = toObject(object);
return object[key] === value && (typeof value != 'undefined' || (key in object)); return object[key] === value && (value !== undefined || (key in object));
}; };
} }
} }
@@ -2521,7 +2521,7 @@
object = toObject(object); object = toObject(object);
} }
return object[key] === value return object[key] === value
? (typeof value != 'undefined' || (key in object)) ? (value !== undefined || (key in object))
: baseIsEqual(value, object[key], null, true); : baseIsEqual(value, object[key], null, true);
}; };
} }
@@ -2551,12 +2551,12 @@
} }
var value = object[key], var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined, result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined'; isCommon = result === undefined;
if (isCommon) { if (isCommon) {
result = srcValue; result = srcValue;
} }
if ((isSrcArr || typeof result != 'undefined') && if ((isSrcArr || result !== undefined) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) { (isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result; object[key] = result;
} }
@@ -2591,7 +2591,7 @@
} }
var value = object[key], var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined, result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined'; isCommon = result === undefined;
if (isCommon) { if (isCommon) {
result = srcValue; result = srcValue;
@@ -2747,7 +2747,7 @@
if (start < 0) { if (start < 0) {
start = -start > length ? 0 : (length + start); start = -start > length ? 0 : (length + start);
} }
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) { if (end < 0) {
end += length; end += length;
} }
@@ -3019,7 +3019,7 @@
var low = 0, var low = 0,
high = array ? array.length : 0, high = array ? array.length : 0,
valIsNaN = value !== value, valIsNaN = value !== value,
valIsUndef = typeof value == 'undefined'; valIsUndef = value === undefined;
while (low < high) { while (low < high) {
var mid = floor((low + high) / 2), var mid = floor((low + high) / 2),
@@ -3029,7 +3029,7 @@
if (valIsNaN) { if (valIsNaN) {
var setLow = isReflexive || retHighest; var setLow = isReflexive || retHighest;
} else if (valIsUndef) { } else if (valIsUndef) {
setLow = isReflexive && (retHighest || typeof computed != 'undefined'); setLow = isReflexive && (retHighest || computed !== undefined);
} else { } else {
setLow = retHighest ? (computed <= value) : (computed < value); setLow = retHighest ? (computed <= value) : (computed < value);
} }
@@ -3056,7 +3056,7 @@
if (typeof func != 'function') { if (typeof func != 'function') {
return identity; return identity;
} }
if (typeof thisArg == 'undefined') { if (thisArg === undefined) {
return func; return func;
} }
switch (argCount) { switch (argCount) {
@@ -3531,7 +3531,7 @@
*/ */
function createForEach(arrayFunc, eachFunc) { function createForEach(arrayFunc, eachFunc) {
return function(collection, iteratee, thisArg) { return function(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection)) return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee) ? arrayFunc(collection, iteratee)
: eachFunc(collection, bindCallback(iteratee, thisArg, 3)); : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
}; };
@@ -3546,7 +3546,7 @@
*/ */
function createForIn(objectFunc) { function createForIn(objectFunc) {
return function(object, iteratee, thisArg) { return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') { if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3); iteratee = bindCallback(iteratee, thisArg, 3);
} }
return objectFunc(object, iteratee, keysIn); return objectFunc(object, iteratee, keysIn);
@@ -3562,7 +3562,7 @@
*/ */
function createForOwn(objectFunc) { function createForOwn(objectFunc) {
return function(object, iteratee, thisArg) { return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') { if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3); iteratee = bindCallback(iteratee, thisArg, 3);
} }
return objectFunc(object, iteratee); return objectFunc(object, iteratee);
@@ -3609,7 +3609,7 @@
function createReduce(arrayFunc, eachFunc) { function createReduce(arrayFunc, eachFunc) {
return function(collection, iteratee, accumulator, thisArg) { return function(collection, iteratee, accumulator, thisArg) {
var initFromArray = arguments.length < 3; var initFromArray = arguments.length < 3;
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection)) return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee, accumulator, initFromArray) ? arrayFunc(collection, iteratee, accumulator, initFromArray)
: baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc); : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
}; };
@@ -3878,7 +3878,7 @@
? customizer(othValue, arrValue, index) ? customizer(othValue, arrValue, index)
: customizer(arrValue, othValue, index); : customizer(arrValue, othValue, index);
} }
if (typeof result == 'undefined') { if (result === undefined) {
// Recursively compare arrays (susceptible to call stack limits). // Recursively compare arrays (susceptible to call stack limits).
if (isLoose) { if (isLoose) {
var othIndex = othLength; var othIndex = othLength;
@@ -3977,7 +3977,7 @@
? customizer(othValue, objValue, key) ? customizer(othValue, objValue, key)
: customizer(objValue, othValue, key); : customizer(objValue, othValue, key);
} }
if (typeof result == 'undefined') { if (result === undefined) {
// Recursively compare objects (susceptible to call stack limits). // Recursively compare objects (susceptible to call stack limits).
result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB); result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
} }
@@ -4519,7 +4519,7 @@
baseForIn(value, function(subValue, key) { baseForIn(value, function(subValue, key) {
result = key; result = key;
}); });
return typeof result == 'undefined' || hasOwnProperty.call(value, result); return result === undefined || hasOwnProperty.call(value, result);
} }
/** /**
@@ -6354,7 +6354,7 @@
if (thisArg && isIterateeCall(collection, predicate, thisArg)) { if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null; predicate = null;
} }
if (typeof predicate != 'function' || typeof thisArg != 'undefined') { if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = getCallback(predicate, thisArg, 3); predicate = getCallback(predicate, thisArg, 3);
} }
return func(collection, predicate); return func(collection, predicate);
@@ -7168,7 +7168,7 @@
if (thisArg && isIterateeCall(collection, predicate, thisArg)) { if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null; predicate = null;
} }
if (typeof predicate != 'function' || typeof thisArg != 'undefined') { if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = getCallback(predicate, thisArg, 3); predicate = getCallback(predicate, thisArg, 3);
} }
return func(collection, predicate); return func(collection, predicate);
@@ -8212,7 +8212,7 @@
if (typeof func != 'function') { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0); start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
return function() { return function() {
var args = arguments, var args = arguments,
index = -1, index = -1,
@@ -8681,7 +8681,7 @@
return value === other; return value === other;
} }
var result = customizer ? customizer(value, other) : undefined; var result = customizer ? customizer(value, other) : undefined;
return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result; return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
} }
/** /**
@@ -8842,7 +8842,7 @@
value = source[key]; value = source[key];
if (isStrictComparable(value)) { if (isStrictComparable(value)) {
return value === object[key] && (typeof value != 'undefined' || (key in object)); return value === object[key] && (value !== undefined || (key in object));
} }
} }
var values = Array(length), var values = Array(length),
@@ -9077,7 +9077,7 @@
* // => false * // => false
*/ */
function isUndefined(value) { function isUndefined(value) {
return typeof value == 'undefined'; return value === undefined;
} }
/** /**
@@ -9162,7 +9162,7 @@
* *
* // using a customizer callback * // using a customizer callback
* var defaults = _.partialRight(_.assign, function(value, other) { * var defaults = _.partialRight(_.assign, function(value, other) {
* return typeof value == 'undefined' ? other : value; * return _.isUndefined(value) ? other : value;
* }); * });
* *
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
@@ -9498,7 +9498,7 @@
var pathKey = isArray(path) ? undefined : (path + ''), var pathKey = isArray(path) ? undefined : (path + ''),
result = baseGet(object, toPath(path), pathKey); result = baseGet(object, toPath(path), pathKey);
return typeof result == 'undefined' ? defaultValue : result; return result === undefined ? defaultValue : result;
} }
/** /**
@@ -9528,7 +9528,7 @@
return false; return false;
} }
var pathKey = isArray(path) ? undefined : (path + ''), var pathKey = isArray(path) ? undefined : (path + ''),
result = typeof pathKey != 'undefined' && hasOwnProperty.call(object, path); result = pathKey !== undefined && hasOwnProperty.call(object, path);
if (!result && !isKey(path)) { if (!result && !isKey(path)) {
path = toPath(path); path = toPath(path);
@@ -9948,7 +9948,7 @@
path = last(path); path = last(path);
} }
var result = object == null ? undefined : toObject(object)[path]; var result = object == null ? undefined : toObject(object)[path];
if (typeof result == 'undefined') { if (result === undefined) {
result = defaultValue; result = defaultValue;
} }
return isFunction(result) ? result.call(object) : result; return isFunction(result) ? result.call(object) : result;
@@ -10301,7 +10301,7 @@
target = (target + ''); target = (target + '');
var length = string.length; var length = string.length;
position = typeof position == 'undefined' position = position === undefined
? length ? length
: nativeMin(position < 0 ? 0 : (+position || 0), length); : nativeMin(position < 0 ? 0 : (+position || 0), length);
@@ -12121,7 +12121,7 @@
start = start == null ? 0 : (+start || 0); start = start == null ? 0 : (+start || 0);
var result = start < 0 ? this.takeRight(-start) : this.drop(start); var result = start < 0 ? this.takeRight(-start) : this.drop(start);
if (typeof end != 'undefined') { if (end !== undefined) {
end = (+end || 0); end = (+end || 0);
result = end < 0 ? result.dropRight(-end) : result.take(end - start); result = end < 0 ? result.dropRight(-end) : result.take(end - start);
} }