Skip to content

Instantly share code, notes, and snippets.

@Gaubee
Last active March 1, 2018 03:02
Show Gist options
  • Save Gaubee/6533988 to your computer and use it in GitHub Desktop.
Save Gaubee/6533988 to your computer and use it in GitHub Desktop.
mix to javascript Object
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