can.Object.same

  • function
 

Checks if two objects are the same.

can.Object.same(a, b, compares, aParent, bParent, deep)

Parameters

  1. a {Object}

    An object to compare against b.

  2. b {Object}

    An object to compare against a.

  3. compares {Object}Optional

    An object that specifies how to compare properties. The keys of the compares object are names of properties in the objects to compare, and the values are functions that compare those properties. You can also pass 'i' to compare values as case-insensitive strings, or null not to compare the properties at all.

Returns

{Object}

Whether the two objects have the same properties and values.

  • boolean

This function does not work with objects that create circular references.

Examples

can.Object.same({name: "Justin"}, {name: "JUSTIN"}) //-> false

// ignore the name property
can.Object.same({name: "Brian"}, {name: "JUSTIN"}, {name: null}) //-> true

// ignore case
can.Object.same({name: "Justin"}, {name: "JUSTIN"}, {name: "i"}) //-> true

// deep rule
can.Object.same({ person : { name: "Justin" } },
    { person : { name: "JUSTIN" } },
    { person : { name: "i"      } }) //-> true

// supplied compare function
can.Object.same({age: "Thirty"},
    {age: 30},
    {age: function( a, b ){
    if( a == "Thirty" ) {
        a = 30
    }
    if( b == "Thirty" ) {
        b = 30
    }
    return a === b;
}})      //-> true