-
-
Save goliatone/6974868 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 util = exports || {}; | |
util.mergeDeep = function (A, B, depth) { | |
var forever = depth == null; | |
for (var p in B) { | |
if (B[p] != null && B[p].constructor==Object && (forever || depth > 0)) { | |
A[p] = util.mergeDeep( | |
A.hasOwnProperty(p) ? A[p] : {}, | |
B[p], | |
forever ? null : depth-1 | |
); | |
} else { | |
A[p] = B[p]; | |
} | |
} | |
return A; | |
} | |
util.merge = function(A, B) { | |
return util.mergeDeep(A, B, 0); | |
} | |
util.mergeCopy = function(A, B, depth) { | |
var A_copy = util.mergeDeep({}, A); | |
return util.mergeDeep(A_copy, B, depth); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment