Is there a simple way to test equality of objects in CoffeeScript?
Or more correctly - test if the properties of two objects are identical.
With these objects:
obj1 =
name: "John Doe"
age: "3.14"
obj2 =
name: "John Doe"
age: "3.14"
This evaluates false, as expected:
obj1 == obj2
For now I'm using Underscore's isEqual
Objects are equal when they have the same state (usually comparing variables). Objects are identical when they share the class identity. For example, the expression obj1==obj2 tests the identity, not equality.
The Comparison Algorithm — Object.is() The Object.is() algorithm determines whether two values are the same if: Both values are undefined or null . Both values are either true or false . Both values are Strings having the same characters, length, and order.
Stringify() method. We cannot just implement “==” or “===” operator to compare two objects. The better way to do the comparison is to use JSON. Stringify and compare the objects.
Nope. CoffeeScript doesn't provide this as a language feature, so using a library like Underscore.js is your best option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With