Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing objects with empty prototypes (no hasOwnProperty method) #7

Closed
denisnd opened this issue Apr 11, 2017 · 2 comments
Closed

Comments

@denisnd
Copy link

denisnd commented Apr 11, 2017

I'm using deep-object-diff to compare objects generated by query-string. Structures returned by its parser have no hasOwnProperty method (sindresorhus/query-string#47) and so deep-object-diff can't work on them as it relies on the method.

Steps to reproduce:

var deepObjectDiff = require('deep-object-diff');

var a = Object.create(null);
a.foo = 'bar;

var b = Object.create(null);
b.foo = 'baz';

console.log( deepObjectDiff.diff(a, b) );

Error message:

TypeError: rhs.hasOwnProperty is not a function
    at C:\Users\nd\object-diff\node_modules\deep-object-diff\dist\diff\index.js:55:18
@mattphillips
Copy link
Owner

@denisnd Hey thanks for raising the issue! I've just published a fix in version 1.0.3 so if you try the same code again all should be good 😄.

It will treat the object as a normal JS object that has the .hasOwnProperty function available, this means that it will work on nested structures that are missing this property at any level.

var deepObjectDiff = require('deep-object-diff');

var a = Object.create(null);
a.foo = 'bar';

var b = Object.create(null);
b.foo = 'baz';

console.log( deepObjectDiff.diff(a, b) ); // { foo: 'baz' }

@denisnd
Copy link
Author

denisnd commented Apr 12, 2017

@mattphillips Thank you for quick fixing! Now everything is working fine.

@denisnd denisnd closed this as completed Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants