The YUI Global Object: Combine Data Sets with merge
merge allows you to combine any number of input objects and output a single merged set.
If the input is a single object, the return value will be a shallow copy of the input, meaning that the return value is a different object, but any non-primitive value in the input object is referenced in the returned object.
Click the "Merge" button to generate the merged set, the "Copy" button to create a shallow copy of an object.
set1 = { foo : "foo" };
set2 = { foo : "BAR", bar : "bar" };
set3 = { foo : "FOO", baz : "BAZ" };
result
click Merge or Copy
Using merge
Instantiate YUI
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.
See the clone method to create deep copies of objects.
