mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Use null when comparing null/undefined
for non-strict equals. Saves 2 gzipped bytes. Former-commit-id: d387147685f95cf88a437e678c873181cbcb907f
This commit is contained in:
14
lodash.js
14
lodash.js
@@ -1128,7 +1128,7 @@
|
||||
*/
|
||||
function first(array, n, guard) {
|
||||
if (array) {
|
||||
return (n == undefined || guard) ? array[0] : slice.call(array, 0, n);
|
||||
return (n == null || guard) ? array[0] : slice.call(array, 0, n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1238,7 +1238,7 @@
|
||||
if (!array) {
|
||||
return [];
|
||||
}
|
||||
return slice.call(array, 0, -((n == undefined || guard) ? 1 : n));
|
||||
return slice.call(array, 0, -((n == null || guard) ? 1 : n));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1296,7 +1296,7 @@
|
||||
function last(array, n, guard) {
|
||||
if (array) {
|
||||
var length = array.length;
|
||||
return (n == undefined || guard) ? array[length - 1] : slice.call(array, -n || length);
|
||||
return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1511,7 +1511,7 @@
|
||||
if (!array) {
|
||||
return [];
|
||||
}
|
||||
return slice.call(array, (n == undefined || guard) ? 1 : n);
|
||||
return slice.call(array, (n == null || guard) ? 1 : n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2255,7 +2255,7 @@
|
||||
* // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' }
|
||||
*/
|
||||
var defaults = createIterator(extendIteratorOptions, {
|
||||
'inLoop': 'if (object[index] == undefined)' + extendIteratorOptions.inLoop
|
||||
'inLoop': 'if (object[index] == null)' + extendIteratorOptions.inLoop
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -2525,8 +2525,8 @@
|
||||
// treat `+0` vs. `-0` as not equal
|
||||
return a !== 0 || (1 / a == 1 / b);
|
||||
}
|
||||
// a strict comparison is necessary because `null == undefined`
|
||||
if (a == undefined || b == undefined) {
|
||||
// a strict comparison is necessary because `undefined == null`
|
||||
if (a == null || b == null) {
|
||||
return a === b;
|
||||
}
|
||||
// unwrap any wrapped objects
|
||||
|
||||
Reference in New Issue
Block a user