Skip to content

Instantly share code, notes, and snippets.

@yhk1038
Created April 12, 2018 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhk1038/fdfa436576adc0f41e9893d52ffe3f15 to your computer and use it in GitHub Desktop.
Save yhk1038/fdfa436576adc0f41e9893d52ffe3f15 to your computer and use it in GitHub Desktop.
Patching: replace only changed part in Object structure. (Ex. Can be used to override user options in default options in library whatever you want to make.)
function patching(original, cover) {
Object.keys(cover).forEach(function (key, i) {
if (original.hasOwnProperty(key)) {
if (typeof original[key] === 'object'){
original[key] = patching(original[key], cover[key])
} else {
original[key] = cover[key]
}
}
});
return original;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment