const {
merge,
cloneDeep,
isPlainObject,
defaultsDeep,
mergeWith,
difference,
keys,
omit
} = _;
const getType = val => Object.prototype.toString.call(val);
const customizer = (objValue, srcValue) => {
// 类型相等且都为对象,保留对象中已存在的属性值执行合并
if (isPlainObject(srcValue) && isPlainObject(objValue)) {
return defaultsDeep(objValue, srcValue);
}
// 类型相等且不为对象,直接使用原始值
else if (getType(objValue) === getType(srcValue)) {
return objValue;
}
// 类型不相等,使用新属性值
else {
return srcValue;
}
};
const oldObj = { border: {borderWidth: 1, posi: 11}, 'b': [2], fonta: 1};
const newObj = {border: {borderWidth: 4, borderColor: 'red'}, 'b': [4], fontSize: 1213};
const needKeys = keys(newObj);
const result = mergeWith(oldObj, newObj, customizer);
const newKeys = keys(result);
console.log(difference(needKeys, newKeys));
const data = omit(result, difference(newKeys, needKeys));
console.log(data);
console