Skip to content

Instantly share code, notes, and snippets.

@Driptap
Last active April 13, 2020 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Driptap/6fc6bc4be2018b860306eb28e78ddf30 to your computer and use it in GitHub Desktop.
Save Driptap/6fc6bc4be2018b860306eb28e78ddf30 to your computer and use it in GitHub Desktop.
ES6 Implementation of lodash's cloneDeep function using underscore
/**
* Creates a deep clone of an object using underscore.
*/
import {clone, each, isObject} from 'underscore';
const deepClone = (_obj) => {
let _clone = clone(_obj);
each(_clone, (_val, _key) => {
if (isObject(_val))
_clone[_key] = deepClone(_val);
});
return _clone;
};
export default deepClone;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment