Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 908 Bytes

extend.md

File metadata and controls

31 lines (21 loc) · 908 Bytes

nbd/util/extend

The extend module is a utility function that merges source objects into the target object.

(target, ...sources)

extend() implementation is the same as that in Underscore's _.extend(). The only difference is that instead of using Array.each to loop through the source objects, extend() uses a simple for loop.

For every source object, the object's properties, including all prototype-inherited properties, are copied onto the target.

require(['nbd/util/extend'], function(extend) {
  function Foo() {}
  Foo.prototype.foo = 'bar';

  var x = new Foo();
  x.marco = 'polo';

  var n = {};
  // Copies all properties of x onto n
  extend(n, x);

  // Both true
  n.marco === 'polo';
  n.foo === 'bar';
});

returns Object The target object, after all properties have been copied.