Last active
March 1, 2018 03:02
-
-
Save Gaubee/6533988 to your computer and use it in GitHub Desktop.
mix to javascript Object
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 _mix(sObj, nObj) { | |
var obj_s, obj_n, i; | |
if (sObj instanceof Object && nObj instanceof Object) { | |
for (i in nObj) { | |
if ((obj_s = sObj[i]) !== (obj_n = nObj[i])) {//避免循环 Avoid Circular | |
sObj[i] = _mix(sObj[i], nObj[i]); | |
} | |
} | |
return sObj; | |
} else { | |
return nObj; | |
} | |
}; | |
var a = { | |
a: 'a' | |
} | |
var b = { | |
b: 'b', | |
d:a | |
} | |
a.c = b; | |
console.log(_mix(a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment