JSON 合并

// 模仿 Object.assign()
function
JSON_merge() { var json = {}, args = arguments, copy = function(f, s) { if (!Object.keys(s).length || f === null) return; for (var i in s) { if (typeof s[i] === 'object' && !!s[i]) { f[i] = s[i].constructor === Array ? [] : {}; copy(f[i], s[i]); } else { f[i] = s[i]; } } return f; }; for (var i in args) { if (!args[i] || args[i].constructor !== Object) throw new Error('arguments has issue!'); copy(json, args[i]); } return json; }
原文地址:https://www.cnblogs.com/shanchenba/p/5608953.html