Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created January 24, 2017 14:27
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 jonathantneal/24150d6a5a392291e87de9029cfbe25e to your computer and use it in GitHub Desktop.
Save jonathantneal/24150d6a5a392291e87de9029cfbe25e to your computer and use it in GitHub Desktop.
Object Deep Assign
const isObject = (item) => Object(item) === item && !Array.isArray(item);
const deepAssign = module.exports = (target, ...sources) => {
sources.forEach(
(source) => {
Object.keys(source).map(
(key) => {
target[key] = isObject(target[key]) && isObject(source[key]) ? deepAssign(target[key], source[key]) : source[key];
}
)
}
);
return target;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment