MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/llau8d/javascript_object_merge/gnpzq2t/?context=3
r/learnjavascript • u/beforesemicolon • Feb 16 '21
28 comments sorted by
View all comments
4
My only issue with this snippet is that it allows mutability of the schema that's passed in potentially causing data loss or data integrity issues. I'd definitely add in a check something along the lines of:
if ( typeof a[key] !== typeof b[key] || Array.isArray(a[key]) !== Array.isArray(b[key]) ) throw Error('Non-matching schema');
4
u/Crypticsafe5 Feb 17 '21
My only issue with this snippet is that it allows mutability of the schema that's passed in potentially causing data loss or data integrity issues. I'd definitely add in a check something along the lines of: