mergeOptions.js 608 B

123456789101112131415161718192021
  1. function mergeOptions(parent, child) {
  2. Object.keys(parent)
  3. .forEach((key) => {
  4. const val = parent[key]
  5. const _val = child[key]
  6. if (Array.isArray(_val)) { return false }
  7. if (child[key] === undefined) { child[key] = parent[key] }
  8. if (typeof val === 'object' && typeof _val === 'object') {
  9. child[key] = Object.assign({}, _val, val)
  10. } else if (typeof val === 'function' && typeof _val === 'function') {
  11. child[key] = function(...p) {
  12. val.apply(this, p)
  13. _val.apply(this, p)
  14. }
  15. }
  16. })
  17. }
  18. module.exports = mergeOptions