mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +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:
|
* The wrapper methods that are **not** chainable by default are:
|
||||||
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
|
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
|
||||||
* `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `escape`, `escapeRegExp`,
|
* `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`, `escape`,
|
||||||
* `every`, `find`, `findIndex`, `findKey`, `findLast`, `findLastIndex`,
|
* `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
|
||||||
* `findLastKey`, `first`, `floor`, `get`, `gt`, `gte`, `has`, `identity`,
|
* `findLastIndex`, `findLastKey`, `first`, `floor`, `get`, `gt`, `gte`,
|
||||||
* `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`, `isBoolean`,
|
* `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`,
|
||||||
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
|
* `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
|
||||||
* `isFinite` `isFunction`, `isMatch`, `isMatchWith`, `isNative`, `isNaN`,
|
* `isEqualWith`, `isError`, `isFinite` `isFunction`, `isMatch`, `isMatchWith`,
|
||||||
* `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, `isString`,
|
* `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
|
||||||
* `isUndefined`, `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`,
|
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
|
||||||
* `lt`, `lte`, `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`,
|
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
|
||||||
* `padRight`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`,
|
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
|
||||||
* `result`, `round`, `runInContext`, `shift`, `size`, `snakeCase`, `some`,
|
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
|
||||||
* `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`,
|
* `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
|
||||||
* `startCase`, `startsWith`, `sum`, `sumBy`, `template`, `trim`, `trimLeft`,
|
* `sortedLastIndexBy`, `startCase`, `startsWith`, `sum`, `sumBy`, `template`,
|
||||||
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
* `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`,
|
||||||
|
* and `words`
|
||||||
*
|
*
|
||||||
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
||||||
* otherwise an unwrapped value is returned.
|
* otherwise an unwrapped value is returned.
|
||||||
@@ -7665,6 +7666,40 @@
|
|||||||
return baseClone(value, true, customizer);
|
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`.
|
* Checks if `value` is greater than `other`.
|
||||||
*
|
*
|
||||||
@@ -7862,7 +7897,6 @@
|
|||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @alias eq
|
|
||||||
* @category Lang
|
* @category Lang
|
||||||
* @param {*} value The value to compare.
|
* @param {*} value The value to compare.
|
||||||
* @param {*} other The other value to compare.
|
* @param {*} other The other value to compare.
|
||||||
@@ -7890,7 +7924,6 @@
|
|||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @alias eq
|
|
||||||
* @category Lang
|
* @category Lang
|
||||||
* @param {*} value The value to compare.
|
* @param {*} value The value to compare.
|
||||||
* @param {*} other The other value to compare.
|
* @param {*} other The other value to compare.
|
||||||
@@ -11359,6 +11392,7 @@
|
|||||||
lodash.cloneWith = cloneWith;
|
lodash.cloneWith = cloneWith;
|
||||||
lodash.deburr = deburr;
|
lodash.deburr = deburr;
|
||||||
lodash.endsWith = endsWith;
|
lodash.endsWith = endsWith;
|
||||||
|
lodash.eq = eq;
|
||||||
lodash.escape = escape;
|
lodash.escape = escape;
|
||||||
lodash.escapeRegExp = escapeRegExp;
|
lodash.escapeRegExp = escapeRegExp;
|
||||||
lodash.every = every;
|
lodash.every = every;
|
||||||
@@ -11450,9 +11484,6 @@
|
|||||||
lodash.uniqueId = uniqueId;
|
lodash.uniqueId = uniqueId;
|
||||||
lodash.words = words;
|
lodash.words = words;
|
||||||
|
|
||||||
// Add aliases
|
|
||||||
lodash.eq = isEqual;
|
|
||||||
|
|
||||||
mixin(lodash, (function() {
|
mixin(lodash, (function() {
|
||||||
var source = {};
|
var source = {};
|
||||||
baseForOwn(lodash, function(func, methodName) {
|
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');
|
QUnit.module('lodash.escape');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@@ -7062,10 +7085,6 @@
|
|||||||
skipTest();
|
skipTest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should be aliased', 1, function() {
|
|
||||||
strictEqual(_.eq, _.isEqual);
|
|
||||||
});
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user