mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Make eq its own method.
This commit is contained in:
69
lodash.js
69
lodash.js
@@ -867,20 +867,21 @@
|
||||
*
|
||||
* The wrapper methods that are **not** chainable by default are:
|
||||
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
|
||||
* `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `escape`, `escapeRegExp`,
|
||||
* `every`, `find`, `findIndex`, `findKey`, `findLast`, `findLastIndex`,
|
||||
* `findLastKey`, `first`, `floor`, `get`, `gt`, `gte`, `has`, `identity`,
|
||||
* `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`, `isBoolean`,
|
||||
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
|
||||
* `isFinite` `isFunction`, `isMatch`, `isMatchWith`, `isNative`, `isNaN`,
|
||||
* `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, `isString`,
|
||||
* `isUndefined`, `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`,
|
||||
* `lt`, `lte`, `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`,
|
||||
* `padRight`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`,
|
||||
* `result`, `round`, `runInContext`, `shift`, `size`, `snakeCase`, `some`,
|
||||
* `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`,
|
||||
* `startCase`, `startsWith`, `sum`, `sumBy`, `template`, `trim`, `trimLeft`,
|
||||
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
||||
* `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`, `escape`,
|
||||
* `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
|
||||
* `findLastIndex`, `findLastKey`, `first`, `floor`, `get`, `gt`, `gte`,
|
||||
* `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`,
|
||||
* `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
|
||||
* `isEqualWith`, `isError`, `isFinite` `isFunction`, `isMatch`, `isMatchWith`,
|
||||
* `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
|
||||
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
|
||||
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
|
||||
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
|
||||
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
|
||||
* `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
|
||||
* `sortedLastIndexBy`, `startCase`, `startsWith`, `sum`, `sumBy`, `template`,
|
||||
* `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`,
|
||||
* and `words`
|
||||
*
|
||||
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
||||
* otherwise an unwrapped value is returned.
|
||||
@@ -7665,6 +7666,40 @@
|
||||
return baseClone(value, true, customizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||
* comparison between two values to determine if they are equivalent.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to compare.
|
||||
* @param {*} other The other value to compare.
|
||||
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred' };
|
||||
* var other = { 'user': 'fred' };
|
||||
*
|
||||
* _.eq(object, object);
|
||||
* // => true
|
||||
*
|
||||
* _.eq(object, other);
|
||||
* // => false
|
||||
*
|
||||
* _.eq('a', 'a');
|
||||
* // => true
|
||||
*
|
||||
* _.eq('a', Object('a'));
|
||||
* // => false
|
||||
*
|
||||
* _.eq(NaN, NaN);
|
||||
* // => true
|
||||
*/
|
||||
function eq(value, other) {
|
||||
return value === other || (value !== value && other !== other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is greater than `other`.
|
||||
*
|
||||
@@ -7862,7 +7897,6 @@
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias eq
|
||||
* @category Lang
|
||||
* @param {*} value The value to compare.
|
||||
* @param {*} other The other value to compare.
|
||||
@@ -7890,7 +7924,6 @@
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias eq
|
||||
* @category Lang
|
||||
* @param {*} value The value to compare.
|
||||
* @param {*} other The other value to compare.
|
||||
@@ -11359,6 +11392,7 @@
|
||||
lodash.cloneWith = cloneWith;
|
||||
lodash.deburr = deburr;
|
||||
lodash.endsWith = endsWith;
|
||||
lodash.eq = eq;
|
||||
lodash.escape = escape;
|
||||
lodash.escapeRegExp = escapeRegExp;
|
||||
lodash.every = every;
|
||||
@@ -11450,9 +11484,6 @@
|
||||
lodash.uniqueId = uniqueId;
|
||||
lodash.words = words;
|
||||
|
||||
// Add aliases
|
||||
lodash.eq = isEqual;
|
||||
|
||||
mixin(lodash, (function() {
|
||||
var source = {};
|
||||
baseForOwn(lodash, function(func, methodName) {
|
||||
|
||||
27
test/test.js
27
test/test.js
@@ -3557,6 +3557,29 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.eq');
|
||||
|
||||
(function() {
|
||||
test('should perform a `SameValueZero` comparison of two values', 11, function() {
|
||||
strictEqual(_.eq(), true);
|
||||
strictEqual(_.eq(undefined), true);
|
||||
strictEqual(_.eq(0, -0), true);
|
||||
strictEqual(_.eq(NaN, NaN), true);
|
||||
strictEqual(_.eq(1, 1), true);
|
||||
|
||||
strictEqual(_.eq(null, undefined), false);
|
||||
strictEqual(_.eq(1, Object(1)), false);
|
||||
strictEqual(_.eq(1, '1'), false);
|
||||
strictEqual(_.eq(1, '1'), false);
|
||||
|
||||
var object = { 'a': 1 };
|
||||
strictEqual(_.eq(object, object), true);
|
||||
strictEqual(_.eq(object, { 'a': 1 }), false);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.escape');
|
||||
|
||||
(function() {
|
||||
@@ -7062,10 +7085,6 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should be aliased', 1, function() {
|
||||
strictEqual(_.eq, _.isEqual);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user