Created
December 29, 2016 20:04
-
-
Save melalj/07644cde019006f37d71a3d3a9e75869 to your computer and use it in GitHub Desktop.
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 characters
function extendRecursive() { | |
const dst = {}; | |
let src; | |
const args = [].splice.call(arguments, 0); | |
const toString = ({}).toString; | |
while (args.length > 0) { | |
src = args.splice(0, 1)[0]; | |
if (toString.call(src) === '[object Object]') { | |
Object.keys(src).forEach(p => { | |
if (toString.call(src[p]) === '[object Object]') { | |
dst[p] = extendRecursive(dst[p] || {}, src[p]); | |
} else { | |
dst[p] = src[p]; | |
} | |
}); | |
} | |
} | |
return dst; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment