js 深度复制数组与对象
/**
* 深度复制数组与对象
* @param o {Array|object} 数据包
* @return {Array|object}
*/
let deepCopy = function(o) {
if (o instanceof Array) {
let n = [];
for (let i = 0; i < o.length; ++i) {
n[i] = deepCopy(o[i]);
}
return n;
} else if (o instanceof Object) {
let n = {};
for (let i in o) {
n[i] = deepCopy(o[i]);
}
return n;
} else {
return o;
}
};