moroshko / shallow-equal

Minimalistic shallow equality check for arrays/objects
MIT License
78 stars 8 forks source link

Inheritence is not handled well #3

Closed Pimm closed 1 year ago

Pimm commented 6 years ago

The object implementation essentially checks whether:

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
  }
fivecar commented 1 year ago

A lot of time has passed, but in trying this test case today, it passes. Perhaps this was added a while ago?

Closing this out, now that it (seems to) work.