| 1234567891011121314151617181920 |
- // 深拷贝
- function deepClone(obj) {
- if (typeof obj !== 'object' || obj === null) {
- return obj
- }
- const target = obj.constructor === Array ? [] : {}
- for (var key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- if (typeof obj[key] === 'object') {
- target[key] = deepClone(obj[key]);
- } else {
- target[key] = obj[key];
- }
- }
- }
- return target;
- }
- export {
- deepClone
- }
|