diff icon indicating copy to clipboard operation
diff copied to clipboard

diff() does not detect properties added to functions

Open howard opened this issue 9 years ago • 2 comments

How to reproduce:

var original = {
  obj: {},
  func: function () {}
};
var modified = _.merge({}, original);
modified.obj.added = 'test';
modified.func.added = 'test';

var differences = DeepDiff.diff(original, modified);
console.log(JSON.stringify(differences));
// -> [{"kind":"N","path":["obj","added"],"rhs":"test"}]

Expected output:

[{"kind":"N","path":["obj","added"],"rhs":"test"},{"kind":"N","path":["func","added"],"rhs":"test"}]

The issue occurs in Chrome 48 (I didn't test other browsers or Node yet, but I doubt it makes a difference) with version 0.3.4 of the library, and version 4.11.1 of lodash. Both were downloaded from NPM.

I don't think it's an issue with _.merge(), since that is the best way I have found yet to copy an object, modify the copy, and find the changes using this library. It works great in all scenarios I'm currently working on, except for function properties.

When manually trying to reproduce this issue similar to what's described in Readme.md (by creating two identical objects that have an empty function each), the functions themselves are detected as an edit, regardless of the changed property.

@georgms is interested in this as well.

howard avatar May 12 '16 10:05 howard

Yep. Line #178 prevents it from working the way you expect. The typeof test is too restrictive.

flitbit avatar May 12 '16 13:05 flitbit

:+1:

georgms avatar May 15 '16 08:05 georgms