Function
isEqual (a, b) Boolean public
Module: | @ember/utils |
---|
Defined in packages/@ember/-internals/runtime/lib/is-equal.js:4
import { isEqual } from '@ember/utils';
- a
- Object
- first object to compare
- b
- Object
- second object to compare
- returns
- Boolean
Compares two objects, returning true if they are equal.
import { isEqual } from '@ember/utils'; isEqual('hello', 'hello'); // true isEqual(1, 2); // false
isEqual
is a more specific comparison than a triple equal comparison. It will call the isEqual
instance method on the objects being compared, allowing finer control over when objects should be considered equal to each other.
import { isEqual } from '@ember/utils'; import EmberObject from '@ember/object'; let Person = EmberObject.extend({ isEqual(other) { return this.ssn == other.ssn; } }); let personA = Person.create({name: 'Muhammad Ali', ssn: '123-45-6789'}); let personB = Person.create({name: 'Cassius Clay', ssn: '123-45-6789'}); isEqual(personA, personB); // true
Due to the expense of array comparisons, collections will never be equal to each other even if each of their items are equal to each other.
import { isEqual } from '@ember/utils'; isEqual([4, 2], [4, 2]); // false
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Futils/isEqual