Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test object equality in CoffeeScript?

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

like image 526
mnorrish Avatar asked Nov 21 '12 22:11

mnorrish


People also ask

How do you know if an object is equal?

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.

How do you check if two objects are equal in react?

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.

How do I compare two objects in Node JS?

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.


1 Answers

Nope. CoffeeScript doesn't provide this as a language feature, so using a library like Underscore.js is your best option.

like image 175
Trevor Burnham Avatar answered Oct 18 '22 22:10

Trevor Burnham