YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
YAHOO.lang.merge
YAHOO.lang.merge
YAHOO.lang.merge
allows you to combine any number of input objects and output a single merged set.
Click the Merge button to generate the merged set.
set1 = { foo : "foo" };
set2 = { foo : "BAR", bar : "bar" };
set3 = { foo : "FOO", baz : "BAZ" };
click Merge
YAHOO.lang
comes bundled with the YAHOO Global Object.
1 | <script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script> |
view plain | print | ? |
If you are using any other YUI component on your page, you should already have YAHOO.lang
available.
In the example illustrated above, we merge three object literals in the form of hash tables. Note the key values in later parameters override those in previous parameters.
1 | YAHOO.namespace('example'); |
2 | |
3 | YAHOO.example.set1 = { foo : "foo" }; |
4 | YAHOO.example.set2 = { foo : "BAR", bar : "bar" }; |
5 | YAHOO.example.set3 = { foo : "FOO", baz : "BAZ" }; |
6 | |
7 | YAHOO.example.doMerge = function () { |
8 | var Ye = YAHOO.example; |
9 | |
10 | var merged = YAHOO.lang.merge(Ye.set1, Ye.set2, Ye.set3); |
11 | |
12 | // Output the stringified version of merged |
13 | var result = YAHOO.util.Dom.get('demo_result'); |
14 | result.innerHTML = YAHOO.example.stringifyObj(merged); |
15 | } |
16 | |
17 | YAHOO.util.Event.on('demo_btn','click',YAHOO.example.doMerge); |
view plain | print | ? |
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.
Copyright © 2013 Yahoo! Inc. All rights reserved.