shallow-equal icon indicating copy to clipboard operation
shallow-equal copied to clipboard

Inheritence is not handled well

Open Pimm opened this issue 7 years ago • 0 comments

The object implementation essentially checks whether:

  • a and b have the same number of own properties, and
  • all of the own properties in a equal any kind of properties in b, including inherited ones.

Because the implementation does not check whether the property in b is its own or not, it can be fooled. Try adding this test case:

  {
    should: 'return false for the false king',
    objA: {
      crownWearer: true
    },
    objB: (function createFalseKing() {
      var spider = {
        crownWearer: true
      }

      function FalseKing() {
        this.objective = 'world domination';
      }

      FalseKing.prototype = spider;

      return new FalseKing();
    })(),
    result: false
  }

Pimm avatar May 14 '18 13:05 Pimm