智能照明系统APP-本地串口
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.
LightingSystemApp-serial/.svn/pristine/c7/c76efc7e3c94fc99bbab7ba6588...

40 lines
1.3 KiB

3 years ago
/**
* https://github.com/swan-team/swan-js/blob/61e2a63f7aa576b5daafbe77fdfa7c65b977060c/src/utils/index.js
*/
const _toString = Object.prototype.toString
/**
* 深度assign的函数
* @param {Object} targetObject 要被拷贝的目标对象
* @param {Object} originObject 拷贝的源对象
* @return {Object} merge后的对象
*/
export const deepAssign = (targetObject = {}, originObject) => {
const originType = _toString.call(originObject)
if (originType === '[object Array]') {
targetObject = originObject.slice(0)
return targetObject
} else if (originType === '[object Object]') {
for (const key in originObject) {
targetObject[key] = deepAssign(targetObject[key], originObject[key])
}
return targetObject
} else if (originType === '[object Date]') {
return new Date(originObject.getTime())
} else if (originType === '[object RegExp]') {
const target = String(originObject)
const lastIndex = target.lastIndexOf('/')
return new RegExp(target.slice(1, lastIndex), target.slice(lastIndex + 1))
}
return originObject
}
/**
* 深度拷贝逻辑,不同于lodash等库,但是与微信一致
* @param {*} [originObj] 原对象
* @return {Object|Array} 拷贝结果
*/
export const deepClone = originObj => {
return deepAssign(_toString.call(originObj) === '[object Array]' ? [] : {}, originObj)
}