kingjs/descriptor.merge
@Merges descriptor property values into this
from delta
using a callback to resolve conflicts.
Usage
Copy properties from source
to target
overwriting any existing values like this:
var merge = require('@kingjs/descriptor.merge');
var target = {
a: 0,
b: 1,
};
var source = {
b: 2,
c: 3
};
function resolve(right, left) {
return right;
}
merge.call(target, source, resolve);
target;
result:
{
a: 0,
b: 2,
c: 3
}
API
declare function merge(
this: Descriptor,
delta?: Descriptor,
resolve?: (this, left, right, name: string) => any,
thisArg?
): any
Interfaces
-
Descriptor
: see @kingjs/descriptor
Parameters
-
this
: An object into which properties are merged. -
delta
: An object whose properties are merged intothis
. -
resolve
: Invoked when merging into an existing value. Returns the merged value. If not supplied, then the existing value is taken.-
left
: The existing value. -
right
: The new value. -
name
: The name of the conflicting property.
-
-
thisArg
: Thethis
argument to pass tocallback
.write and returned instead ofthis
.
Returns
Returns this
after merging properties from delta
.
Install
With npm installed, run
$ npm install @kingjs/descriptor.merge
License
MIT