29 lines
642 B
JavaScript
29 lines
642 B
JavaScript
|
|
// 数据合并
|
|
export function mergeRecursive(source, target) {
|
|
for (var p in target) {
|
|
try {
|
|
if (target[p].constructor == Object) {
|
|
source[p] = mergeRecursive(source[p], target[p]);
|
|
} else {
|
|
source[p] = target[p];
|
|
}
|
|
} catch (e) {
|
|
source[p] = target[p];
|
|
}
|
|
}
|
|
|
|
// source = target
|
|
// for (var p in target) {
|
|
// try {
|
|
// if (target[p].constructor == Object) {
|
|
// source[p] = mergeRecursive(source[p], target[p]);
|
|
// } else {
|
|
// source[p] = target[p];
|
|
// }
|
|
// } catch (e) {
|
|
// source[p] = target[p];
|
|
// }
|
|
// }
|
|
return source;
|
|
}; |