mirror of
https://github.com/youzan/vant.git
synced 2025-12-22 01:07:29 +08:00
[type] scroll (#2704)
This commit is contained in:
30
packages/utils/deep-assign.ts
Normal file
30
packages/utils/deep-assign.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/* eslint-disable no-use-before-define */
|
||||
import { isDef, isObj } from '.';
|
||||
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
|
||||
type Object = {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
function assignKey(to: Object, from: Object, key: string) {
|
||||
const val = from[key];
|
||||
|
||||
if (!isDef(val) || (hasOwnProperty.call(to, key) && !isDef(to[key]))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasOwnProperty.call(to, key) || !isObj(val)) {
|
||||
to[key] = val;
|
||||
} else {
|
||||
to[key] = assign(Object(to[key]), from[key]);
|
||||
}
|
||||
}
|
||||
|
||||
export default function assign(to: Object, from: Object) {
|
||||
Object.keys(from).forEach(key => {
|
||||
assignKey(to, from, key);
|
||||
});
|
||||
|
||||
return to;
|
||||
}
|
||||
Reference in New Issue
Block a user