TkAstral3D/packages/sdk/lib/utils/common/object.ts
2025-10-04 23:36:07 +08:00

19 lines
574 B
TypeScript

/**
* 将对象source的值深度遍历赋值给target对象相同key
* @param target
* @param source
*/
export function deepAssign(target, source) {
for (const key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key])) {
if (!target[key]){
target[key] = {};
}
deepAssign(target[key], source[key]);
} else {
target[key] = source[key];
}
}
}
}