Skip to content

Commit

Permalink
deepEqual: Remove instanceof Object check (#529)
Browse files Browse the repository at this point in the history
This is useful when the Object constructor might differ from object to
object. This has been true for me when hacking on Gecko -- the objects
that make it to the deepEqual function are instances of Object (from the
kinto-http-client scope), but the reference Object points to
Object (from the kinto-offline-client scope). We might also expect this
sort of thing to come up when someone uses Kinto in a WebExtension; the
scope of the WebExtension will be different from the scope of the code
running on the page. Instead of using the "instanceof Object" check, use
the "typeof" check. Unfortunately, because JavaScript, null and
undefined also have typeof "object", so try to rule out falsy things
explicitly.
  • Loading branch information
glasserc authored Aug 30, 2016
1 parent c42fdba commit 2419ac5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function deepEqual(a, b) {
if (typeof(a) !== typeof(b)) {
return false;
}
if (!(a instanceof Object) || !(b instanceof Object)) {
if (!(a && typeof a == "object") || !(b && typeof b == "object")) {
return false;
}
if (Object.keys(a).length !== Object.keys(b).length) {
Expand Down

0 comments on commit 2419ac5

Please sign in to comment.