当前位置:网站首页>Deep merge object deep copy of vant source code parsing
Deep merge object deep copy of vant source code parsing
2022-07-05 20:58:00 【The legend of Feng】
Source code
Merge the properties of two objects , Deep objects can also
function isDef(value: any): boolean {
// value:any Indicates that the parameter passed in is of any type boolean Indicates that the return value is boolean type
return value !== undefined && value !== null;
// The value passed in cannot be undefined Nor is null
}
// in 15.686s 0.486s
function isObj(x: any): boolean {
debugger
// Judge whether a value is object type
// Incoming parameter yes any Any type i
// The return value is boolean
const type = typeof x;
// typeof Judge data type
// typeof When judging the data type null It's also object therefore type Not for null
// The function is also object
return x !== null && (type === 'object' || type === 'function');
}
const { hasOwnProperty } = Object.prototype;
// Determine whether an object contains an attribute ( Does not include attributes on the object prototype )
type objectType = {
[key: string]: any;
}
function assignKey(to: objectType, from: objectType, key: string) {
const val = from[key];
// Get the old data Some key Value
if (!isDef(val)) {// At present key Corresponding Value of old data yes undefined Just return
return;
}
if (!hasOwnProperty.call(to, key) || !isObj(val)) {
// If the target object's This key If it doesn't exist The old data corresponds to key value Assign a value to Target audience to
to[key] = val;
} else {
to[key] = deepAssign(Object(to[key]), from[key]);
}
}
function deepAssign(to: objectType, from: objectType) {
Object.keys(from).forEach(key => {
assignKey(to, from, key);
});
return to;
}
test
let toInfo={
name:"123",
age:'16',
more:{
hobby:' To play basketball ',
address:' Hefei '
},
color:'red'
}
let fromInfo={
name:"12343553",
age:'16545353',
more:{
hobby:' To play basketball 5353',
address:' Hefei 5353'
},
sex:' male '
}
let result: objectType = deepAssign(toInfo,fromInfo)
console.log("result",result)Deep copy
import { deepAssign } from './deep-assign';
export function deepClone(obj: object): object {
if (Array.isArray(obj)) {
return obj.map(item => deepClone(item));
}
if (typeof obj === 'object') {
return deepAssign({}, obj);
}
return obj;
}
边栏推荐
- 实现浏览页面时校验用户是否已经完成登录的功能
- Monorepo管理方法论和依赖安全
- 学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
- Norgen AAV extractant box instructions (including features)
- Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
- 珍爱网微服务底层框架演进从开源组件封装到自研
- Determine the best implementation of horizontal and vertical screens
- systemd-resolved 开启 debug 日志
- Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
- Binary search
猜你喜欢

PHP deserialization +md5 collision

Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral

Duchefa d5124 md5a medium Chinese and English instructions

The development of research tourism practical education helps the development of cultural tourism industry

重上吹麻滩——段芝堂创始人翟立冬游记

PHP反序列化+MD5碰撞

Abnova total RNA Purification Kit for cultured cells Chinese and English instructions

【案例】定位的运用-淘宝轮播图

Cutting edge technology for cultivating robot education creativity

Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
随机推荐
基於flask寫一個接口
五层网络协议
shell编程100例
启牛2980有没有用?开户安全吗、
【案例】元素的显示与隐藏的运用--元素遮罩
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
示波器探头对信号源阻抗的影响
When a user logs in, there is often a real-time drop-down box. For example, entering an email will @qq com,@163. com,@sohu. com
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
Écrire une interface basée sur flask
最长摆动序列[贪心练习]
Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
Pytorch实战——MNIST数据集手写数字识别
线程池的使用
matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
PVC 塑料片BS 476-6 火焰传播性能测定
LeetCode_哈希表_困难_149. 直线上最多的点数
珍爱网微服务底层框架演进从开源组件封装到自研
php中explode函数存在的陷阱
教你自己训练的pytorch模型转caffe(二)