(require("mixing"))(destination, source [, settings])
Copy/add all fields and functions from source objects into the target object. As a result the target object may be modified.
Parameters:
Name | Type | Argument | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
destination |
Object | function | The target object into which fields and functions will be copied. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
source |
Array | Object | Array of source objects or just one object whose contents will be copied.
If a source is a falsy value (e.g. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
settings |
Object |
<optional> |
Operation settings. Fields are names of settings, their values are the corresponding values of settings. The following settings are being supported.
overwrite , filter and change function:
copy , except and filter settings can be used together.
In such situation a field will be copied only when the field satisfies to all settings
(i.e. belongs to copied elements, not in exceptions and conforms to filter). |
Returns:
Modified target object.
- Type
- Object
Methods
-
<static> assign(destination, source)
-
Copy values of all of the own properties from one or more source objects to the target object (similar to
Object.assign
).
This function is a "wrap" for the following code:mixing(destination, Array.prototype.slice.call(arguments, 1), {overwrite: true, ownProperty: true});
Parameters:
Name Type Argument Description destination
Object | function The target object into which fields and functions will be copied.
source
Object <repeatable>
An object whose contents will be copied. If a source is a falsy value (e.g.
null
orundefined
), the source will be skipped.Returns:
Modified
target
object.- Type
- Object
-
<static> change(source, change)
-
Change values of fields of given object.
This function is a "wrap" for the following code:mixing(source, source, {change: change, overwrite: true, oneSource: true});
Parameters:
Name Type Description source
Array | Object An array or an object whose fields should be modified.
change
function | Object A function or an object that specifies the modification. See mixing for details.
Returns:
Modified
source
object.- Type
- Object
-
<static> clone( [settings])
-
Make a copy of
this
object.
This function is a "wrap" for the following code:
It can be transferred to an object to use as a method.var copy = mixing({}, this, settings);
Parameters:
Name Type Argument Description settings
Object <optional>
Operation settings. See mixing for details.
Returns:
Newly created object containing contents of
this
object.- Type
- Object
-
<static> copy(source [, settings])
-
Make a copy of source object(s).
This function is a "wrap" for the following code:var copy = mixing({}, source, settings);
Parameters:
Name Type Argument Description source
Array | Object Array of source objects or just one object whose contents will be copied.
settings
Object <optional>
Operation settings. See mixing for details.
Returns:
Newly created object containing contents of source objects.
- Type
- Object
-
<static> filter(filter)
-
Filter
this
object.
This function is a "wrap" for the following code:
It can be transferred to an object to use as a method.var result = mixing({}, this, {filter: filter});
Parameters:
Name Type Description filter
function | Object Filter function to select fields or object that represents operation settings including filter function. See mixing for details.
Returns:
Newly created object containing fields of
this
object for which filter function returns true.- Type
- Object
-
<static> getSettings()
-
Return default settings that were set earlier.
Returns:
Default settings that were set earlier or
undefined / null
if default settings were not set.- Type
- Object | undefined
-
<static> map(change)
-
Copy and change values of fields of
this
object.
This function is a "wrap" for the following code:
It can be transferred to an object to use as a method.var result = mixing({}, this, {change: change});
Parameters:
Name Type Description change
function | Object Function to change values of copied fields or object that represents operation settings including change function. See mixing for details.
Returns:
Newly created object containing fields of
this
object with changed values.- Type
- Object
-
<static> mix(source [, settings])
-
Copy/add all fields and functions from source objects into
this
object. As a resultthis
object may be modified.
This function is a "wrap" for the following code:
It can be transferred to an object to use as a method.mixing(this, source, settings);
Parameters:
Name Type Argument Description source
Array | Object Array of source objects or just one object whose contents will be copied.
settings
Object <optional>
Operation settings. See mixing for details.
Returns:
Modified
this
object.- Type
- Object
-
<static> mixToItems(destinationList, source [, settings])
-
Copy fields from source object(s) into every object item of given array.
Parameters:
Name Type Argument Description destinationList
Array An array whose items should be modified.
source
Array | Object Array of source objects or just one object whose contents will be copied.
settings
Object <optional>
Operation settings that will be applied to every copying. See mixing for details.
Returns:
Original
destinationList
with possibly modified object items.- Type
- Array
-
<static> setSettings( [settings])
-
Set (redefine, reset) default settings that should be used for subsequent mixing calls.
Parameters:
Name Type Argument Description settings
Object | undefined <optional>
Default settings that should be used for subsequent mixing calls. Initial default values will be used for settings that are not specified in the passed object. Pass
undefined
,null
, non-object or to call without parameter to reset default settings to initial values. -
<static> update(change)
-
Change values of fields of
this
object.
This function is a "wrap" for the following code:
It can be transferred to an object to use as a method.mixing.change(this, change);
Parameters:
Name Type Description change
function | Object A function or an object that specifies the modification. See mixing for details.
Returns:
Modified
this
object.- Type
- Object