question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't compare object with prototype

See original GitHub issue
dequal(Object.create({x:1}), {x:1}) //false

Other deep equal libs do that fine.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Apr 18, 2020

@dy that is not what you opened an issue about.

Also, Arrays can be strictly deep-equal with that syntax, but not NodeLists because that’s of different type (iterator). Iterators are not currently supported but will be in the new mode I’ll ship soon, which already includes Map and Set support. I may generalize that to any Iterator type.

What you can do in the meantime, since it sounds like you’re explicitly checking for childNodes, is cast the NodeList to an Array via list = Array.from(el.childNodes); – that will then work out of the box.

Proof:

var dequal = require("dequal")
var fequal = require("fast-deep-equal")
var lodash = require("lodash");

var items = [1, 2, 3]

console.log('dequal:', dequal(items, [...items])); //=> true
console.log('fequal:', fequal(items, [...items])); //=> true
console.log('lodash:', lodash.isEqual(items, [...items])); //=> true
1reaction
lukeedcommented, Apr 17, 2020

Hey,

I was on the move when I first looked at this issue. This should be false.

An object with x on the prototype is strictly not the same thing as an object with an x (writable, enumerable) property.

Not sure what other libraries you were looking at/comparing with, but if they’re meant to be a “deep equality” check, then they have a bug.

Confirmed with two others below:

const fequal = require("fast-deep-equal");
const dequal = require("dequal");
const lodash = require("lodash");

console.log(`fast: ${fequal(Object.create({x:1}), {x:1})}`); //=> false
console.log(`dequal: ${dequal(Object.create({x:1}), {x:1})}`); //=> false
console.log(`lodash: ${lodash.isEqual(Object.create({x:1}), {x:1})}`); //=> false

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript compare object prototype and sum them
JavaScript compare object prototype and sum them ... This line new Mes(mes, lluvia); is unnecessary. It creates an object but doesn't save it ......
Read more >
Comparing object with null prototype and objects derived from ...
How about two objects with null prototypes? The second test should pass right? It's complaining that the object doesn't have hasOwnProperty ...
Read more >
Object.prototype.isPrototypeOf() - JavaScript - MDN Web Docs
The isPrototypeOf() method checks if an object exists in another object's prototype chain. Note: isPrototypeOf() differs from the instanceof ...
Read more >
Getting the differences between two objects with vanilla JS
First, we'll setup our function, passing in our original object and the object to compare it to as arguments. If the second object...
Read more >
Understanding Prototypes and Inheritance in JavaScript
At the end of the prototype chain is Object.prototype . All objects inherit the properties and methods of Object . Any attempt to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found