Changeset 4002:8179279ed508 for inc/js
- Timestamp:
- 07/02/19 10:16:29 (6 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/js/util.js
r3915 r4002 1 /* exported getData*/1 /*exported getData, isObject, mergeDeep */ 2 2 'use strict'; 3 3 … … 18 18 return data; 19 19 }; 20 21 var isObject = isObject || function isObject(item) { 22 return (item && typeof item === 'object' && !Array.isArray(item)); 23 }; 24 25 /** 26 * Deep merge two objects. 27 * @param target 28 * @param ...sources 29 */ 30 var mergeDeep = mergeDeep || function mergeDeep(target, ...sources) { 31 if (!sources.length) return target; 32 const source = sources.shift(); 33 if (isObject(target) && isObject(source)) { 34 for (const key in source) { 35 if (isObject(source[key])) { 36 if (!target[key]) Object.assign(target, { [key]: {} }); 37 mergeDeep(target[key], source[key]); 38 } else { 39 Object.assign(target, { [key]: source[key] }); 40 } 41 } 42 } 43 return mergeDeep(target, ...sources); 44 };
Note: See TracChangeset
for help on using the changeset viewer.