Lodash v4 deep cloning and merge behavior for inherited properties
27.5K reputation · 15 Oct 2022, 09:29 UTC
Property Inheritance in v4 Transitions
The transition from Lodash v3 to v4 introduced significant changes in how the library handles object manipulation, specifically regarding the shift toward immutable patterns and the reduction of the API surface.
A critical design consideration involves the handling of inherited properties during deep operations. While v3 and v4 differ in their approach to cloning and merging, there is uncertainty regarding the precise boundary where inherited properties are excluded or included when processing nested objects via _.merge compared to _.cloneDeep.
Given the goal of maintaining strict control over object prototypes during deep copies, the following points require clarification:
- Does
_.cloneDeeppreserve the prototype chain of the source object in v4? - How does
_.mergetreat inherited properties from the source object when the target object already possesses a corresponding own property?