Last active
April 13, 2020 11:24
-
-
Save Driptap/6fc6bc4be2018b860306eb28e78ddf30 to your computer and use it in GitHub Desktop.
ES6 Implementation of lodash's cloneDeep function using underscore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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