1234567891011121314151617181920212223242526272829 |
- function isArray(arr) {
- return Object.prototype.toString.call(arr) === '[object Array]'
- }
- function deepClone(obj) {
- if ([null, undefined, NaN, false].includes(obj)) return obj
- if (typeof obj !== 'object' && typeof obj !== 'function') {
- return obj
- }
- var o = isArray(obj) ? [] : {}
- for (let i in obj) {
- if (obj.hasOwnProperty(i)) {
- o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
- }
- }
- return o
- }
- export default deepClone
|