You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
848 B
30 lines
848 B
3 years ago
|
const util = {
|
||
|
deepCopy(obj) { // 深拷贝
|
||
|
if (obj == null) {
|
||
|
return null;
|
||
|
}
|
||
|
if (typeof obj !== "object") return obj;
|
||
|
let result;
|
||
|
if (Array.isArray(obj)) {
|
||
|
result = [];
|
||
|
obj.forEach(item => {
|
||
|
result.push(
|
||
|
typeof item === "object" && !(item instanceof Date)
|
||
|
? util.deepCopy(item)
|
||
|
: item
|
||
|
);
|
||
|
});
|
||
|
} else {
|
||
|
result = {};
|
||
|
Object.keys(obj).forEach(key => {
|
||
|
result[key] =
|
||
|
typeof obj[key] === "object" && !(obj[key] instanceof Date)
|
||
|
? util.deepCopy(obj[key])
|
||
|
: obj[key];
|
||
|
});
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export default util;
|