提交 7b3c65c1 编写于 作者: 小刘28's avatar 小刘28 💬

perf:优化空字符串的判断;实现JS的深拷贝;

上级 d1c010ad
......@@ -14,9 +14,12 @@ export default {
* @Return {Boolean} true:为空,false:不为空
**/
isStringEmpty(string = ''){
if(string === undefined || string === null || string.trim().length === 0){
if(string === undefined || string === null){
return true;
}else{
}
if(string.trim().length === 0){
return true;
} else {
return false;
}
},
......
/**
* @Author: xiaozuo28
* @Date: 2022年5月13日08:05:20
* @LastEditors: xiaozuo28
* @LastEditTime: 2022年7月17日08:42:42
* @Description: 数据拷贝处理
**/
export default {
/**
* @Description 深拷贝(数组,对象)
* @Date 2022年7月17日22:08:07
* @Param {Object} obj 待拷贝对象
* @Return {Object} 拷贝后的对象
**/
deepClone(obj) {
//判断拷贝的obj是对象还是数组
let objClone = Array.isArray(obj) ? [] : {};
if (obj && typeof obj === "object") { //obj不能为空,并且是对象或者是数组 因为null也是object
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] && typeof obj[key] === "object") { //obj里面属性值不为空并且还是对象,进行深度拷贝
objClone[key] = deepClone(obj[key]); //递归进行深度的拷贝
} else {
objClone[key] = obj[key]; //直接拷贝
}
}
}
}
return objClone;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册