Created
February 28, 2017 20:14
-
-
Save jgermade/41a12558e8715a708110803724a9bb70 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
var arrayShift = [].shift; | |
function _deep_merge (dest, src) { | |
if( typeof dest !== typeof src ) { | |
return src; | |
} | |
if( src instanceof Array ) { | |
[].push.apply(dest, src); | |
return dest; | |
} | |
if( typeof src === 'object' ) { | |
for( var key in src ) { | |
dest[key] = _deep_merge(dest[key], src[key]); | |
} | |
return dest; | |
} | |
return src; | |
} | |
function _merge () { | |
var dest = arrayShift.call(arguments), | |
src = arrayShift.call(arguments); | |
while( src ) { | |
dest = _deep_merge(dest, src); | |
src = arrayShift.call(arguments); | |
} | |
return dest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment