forked from mattphillips/deep-object-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support diffing keys named like Object.prototype properties
Fixes mattphillips#58. Previously, the code assumed that input objects have a `hasOwnProperty` function, or that at least they will acquire one when passed through `utils.properObject`. However, this assumption is flawed: As noted in issue mattphillips#58, when given input objects have a property on them called `hasOwnProperty`, it overrides the prototype's function property that the code relied on, causing any diffing function to error out with Uncaught TypeError: r.hasOwnProperty is not a function The solution taken here is to forget about `utils.properObject`, and instead introduce `utils.hasOwnProperty` which uses `Object.prototype.hasOwnProperty.call` instead of assuming anything about the input object, and replacing all direct `inputObject.hasOwnProperty` calls with it instead.
- Loading branch information
Showing
8 changed files
with
28 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const isDate = d => d instanceof Date; | ||
export const isEmpty = o => Object.keys(o).length === 0; | ||
export const isObject = o => o != null && typeof o === 'object'; | ||
export const properObject = o => isObject(o) && !o.hasOwnProperty ? { ...o } : o; | ||
export const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters