API Docs for: 1.5.0
Show:

File: src/utils/extend.js

  1. /* globals define */
  2. define([], function () {
  3. "use strict";
  4. /**
  5. * Provides only the `extend` function.
  6. *
  7. * @class extend
  8. * @static
  9. */
  10.  
  11. /**
  12. * Extend the given object with properties of an arbitrary amount of other objects
  13. *
  14. * Override priority is determined using the order the objects are given in
  15. * Each further object has a higher priority then the one before it.
  16. *
  17. * Only actual properties of the given objects will be used not the ones bubbling up
  18. * through the prototype chain.
  19. *
  20. * @method extend
  21. * @static
  22. * @param target
  23. * @param [obj]* Arbitrary amount of objects which will extend the first one
  24. * @return {Object} the extended object
  25. */
  26. var extend = function (target /*, obj, ... */) {
  27. var extensions = Array.prototype.slice.call(arguments, 1);
  28. extensions.forEach(function (extension) {
  29. var key;
  30.  
  31. if (typeof extension !== "object") {
  32. // Skip everything that is not an object
  33. return;
  34. }
  35.  
  36. for (key in extension) {
  37. if (extension.hasOwnProperty(key) && extension[key] !== undefined) {
  38. target[key] = extension[key];
  39. }
  40. }
  41. });
  42.  
  43. return target;
  44. };
  45.  
  46. return extend;
  47. });
  48.