FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.append() function

mixed fcf.append(object|array|Map|Set a_dest, object|array|Map|Set a_source1, ..., object|array|Map|Set a_sourceN)
mixed fcf.append(boolean a_copyMode, object|array|Map|Set a_dest, object|array|Map|Set a_source1, ..., object|array|Map|Set a_sourceN)

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Copies data from sources a_source1 ... a_sourceN to destination a_dest. If the argument a_copyMode is equal to true, a full (recursion) copy of the data is performed with the re-creation of objects

Arguments

boolean a_copyMode
- If the argument is true, then the data is copied recursively, so the recipient gets copies of the objects, not copies of the references to the original.

object|array|Map|Set a_dst
- An object that will be supplemented with additional data

object|array|Map|Set a_source1 ... a_sourceN
- Objects whose data will be supplemented by the receiver
Result
mixed
- Returns the a_dest argument

Example: Function application

{ let dest = {"k1": "v1"}; let source = {"k2": "v2"}; fcf.append(dest, source); console.log(dest); } console.log(""); { let dest = [1]; let source = [2]; fcf.append(dest, source); console.log(dest); } console.log(""); { let dest = new Map(); let source = {"k2": "v2"}; fcf.append(dest, source); console.log(dest); } console.log(""); { let dest = new Set(); dest.add("k1") let source = ["k2"]; fcf.append(dest, source); console.log(dest); }

Output:

{ k1: 'v1', k2: 'v2' } [ 1, 2 ] Map(1) { 'k2' => 'v2' } Set(2) { 'k1', 'k2' }

Example: Copying data with recreating objects

{ let dest = { o: { "k1": "v1" } }; let source = { o: { "new_key": "new_value" } }; fcf.append(true, dest, source); console.log(`dest: `, dest); console.log(`dest.o === source.o: `, dest.o === source.o); }

Output:

dest: { o: { new_key: 'new_value' } } dest.o === source.o: false