mirror of
https://gitee.com/TSpecific/tuniao-ui.git
synced 2026-06-08 12:33:17 +08:00
1e087b5ac3
修复已知bug
29 lines
613 B
JavaScript
29 lines
613 B
JavaScript
/**
|
|
* 判断是否为数组
|
|
*
|
|
* @param {Object} arr
|
|
*/
|
|
function isArray(arr) {
|
|
return Object.prototype.toString.call(arr) === '[object Array]'
|
|
}
|
|
|
|
/**
|
|
* 深度复制数据
|
|
*
|
|
* @param {Object} obj
|
|
*/
|
|
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 |