Example: Combine Data Sets with `merge`

Combine data sets and create shallow copies of objects with merge

set1 = { foo : "foo" };

set2 = { foo : "BAR", bar : "bar" };

set3 = { foo : "FOO", baz : "BAZ" };

Result

click Merge or Copy

Using merge

YUI().use('node', 'dump', function(Y) {
// This method is in the core of the library, so we don't have to use() any
// additional modules to access it. However, this example requires 'node' and 'dump'.

Merging hash tables

When the "Merge" button is clicked, we merge three object literals in the form
of hash tables. Note the key values in later parameters override those in
previous parameters.

Creating Shallow Copies

When the "Copy" button is clicked, we create use merge on a single
object in order to create a shallow clone. The code illustrates the
fact that object properties of the result object are shared with
the input object.