Ei kuvausta

index.js 576B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. var isObject = require('is-extendable');
  3. module.exports = function extend(o/*, objects*/) {
  4. if (!isObject(o)) { o = {}; }
  5. var len = arguments.length;
  6. for (var i = 1; i < len; i++) {
  7. var obj = arguments[i];
  8. if (isObject(obj)) {
  9. assign(o, obj);
  10. }
  11. }
  12. return o;
  13. };
  14. function assign(a, b) {
  15. for (var key in b) {
  16. if (hasOwn(b, key)) {
  17. a[key] = b[key];
  18. }
  19. }
  20. }
  21. /**
  22. * Returns true if the given `key` is an own property of `obj`.
  23. */
  24. function hasOwn(obj, key) {
  25. return Object.prototype.hasOwnProperty.call(obj, key);
  26. }