Fix deepClone edge case

This commit is contained in:
Jy
2019-01-11 14:52:53 +08:00
parent a943631e27
commit 09e2709fa4
2 changed files with 6 additions and 1 deletions

View File

@ -12,7 +12,7 @@ const deepClone = obj => {
Object.keys(clone).forEach(
key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key])
);
return Array.isArray(obj) ? (clone.length = obj.length) && Array.from(clone) : clone;
return Array.isArray(obj) ? Array.from({ length: obj.length }) : clone;
};
```