mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 00:31:20 -08:00
分离工具函数
This commit is contained in:
1 parent
7a84c262da
commit
8ef582f714
22 files changed
+724
-687
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { errorHandle } from './error';
|
||||
|
||||
export function hasOwnProperty(obj, name) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, name);
|
||||
}
|
||||
|
||||
export function proxyPropertys(target, ...sources) {
|
||||
return sources.reduce((result, source) => {
|
||||
Object.getOwnPropertyNames(source).forEach(key => {
|
||||
errorHandle(!hasOwnProperty(result, key), `Target attribute name is duplicated: ${key}`);
|
||||
Object.defineProperty(result, key, Object.getOwnPropertyDescriptor(source, key));
|
||||
});
|
||||
return result;
|
||||
}, target);
|
||||
}
|
||||
|
||||
export function mergeDeep(...objects) {
|
||||
const isObject = item => item && typeof item === 'object' && !Array.isArray(item);
|
||||
return objects.reduce((prev, obj) => {
|
||||
Object.keys(obj).forEach(key => {
|
||||
const pVal = prev[key];
|
||||
const oVal = obj[key];
|
||||
if (Array.isArray(pVal) && Array.isArray(oVal)) {
|
||||
prev[key] = pVal.concat(...oVal);
|
||||
} else if (isObject(pVal) && isObject(oVal) && !(oVal instanceof Element)) {
|
||||
prev[key] = mergeDeep(pVal, oVal);
|
||||
} else {
|
||||
prev[key] = oVal;
|
||||
}
|
||||
});
|
||||
return prev;
|
||||
}, {});
|
||||
}
|
||||
Reference in new issue
Block a user