shallow-extend
A utility function similar to extend()
in underscore
or lo-dash
.
function extend(destination ) {}
Copies properties of all sources to the destination object overriding its own
existing properties. When extending from multiple sources, fields of every next
source will override same named fields of previous sources. Returns the destination object.
Makes only a shallow copy of the source feilds, in contrast to
node-extend or
node-deep-extend.
Examples
Merge and modify:
var source1 = {a: 1, b: 1, c: 1};
var source2 = {b: 2, c: 2};
var source3 = {c: 3};
var destination = extend(source1, source2, source3);
Do not modify anything:
var source1 = {a: 1, b: 1, c: 1};
var source2 = {b: 2, c: 2};
var source3 = {c: 3};
var destination = extend({}, source1, source2, source3);
Managing defaults:
function takesOptions(opts) {
var params = extend({
a: 'default value',
b: 'default value'
}, opts);
}