diff
diff copied to clipboard
diff() does not detect properties added to functions
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.
Yep. Line #178 prevents it from working the way you expect. The typeof test is too restrictive.
:+1: