Created
August 15, 2016 08:31
-
-
Save CodinCat/d2bdc4b721efc8bba01c8c2662b2e15b to your computer and use it in GitHub Desktop.
Revisions
-
CodinCat created this gist
Aug 15, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ function deepClone(obj) { if (Array.isArray(obj)) return obj.map((el) => deepClone(el)) if ( typeof obj !== 'object' || Object.prototype.toString.call(obj) !== '[object Object]' || obj === null ) return obj let clone = {} for (let i in obj) if (obj.hasOwnProperty(i)) clone[i] = deepClone(obj[i]) return clone }