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; }

 

posted @ 2016-06-22 23:14  koala_熊  Views(187)  Comments(0Edit  收藏  举报