starter.js 781 B

123456789101112131415161718192021222324252627282930
  1. (function(window) {
  2. window.CONFIG = {}
  3. })(window);
  4. /**
  5. * 对象属性合并,与 Object.assign 语法不同
  6. * @param target
  7. * @param source
  8. * @returns {{}}
  9. */
  10. function configDeepMerge(target, source) {
  11. var merged = {};
  12. for (var each in source) {
  13. if (target.hasOwnProperty(each) && source.hasOwnProperty(each)) {
  14. if (typeof target[each] == "object" && typeof source[each] == "object") {
  15. merged[each] = configDeepMerge(target[each], source[each]);
  16. } else {
  17. merged[each] = source[each];
  18. }
  19. } else if (source.hasOwnProperty(each)) {
  20. merged[each] = source[each];
  21. }
  22. }
  23. for (var each in target) {
  24. if (!(each in source) && target.hasOwnProperty(each)) {
  25. merged[each] = target[each];
  26. }
  27. }
  28. return merged;
  29. }