<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Prototype JavaScript framework - Hash</title>
  <id>tag:www.prototypejs.org,2008:mephisto/api/hash</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://www.prototypejs.org/feed/api/hash/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.prototypejs.org/api/hash" rel="alternate" type="text/html"/>
  <updated>2007-11-17T15:33:55Z</updated>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-17:17989</id>
    <published>2007-11-17T15:26:00Z</published>
    <updated>2007-11-17T15:33:55Z</updated>
    <category term="Hash"/>
    <category term="1.6"/>
    <link href="http://www.prototypejs.org/api/hash/toobject" rel="alternate" type="text/html"/>
    <title>toObject</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toObject() -&gt; Object&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a cloned, vanilla object.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toObject() -&gt; Object&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a cloned, vanilla object.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ a: 'apple', b: 'banana', c: 'coconut' });
var obj = h.toObject();

Object.inspect(h);
// -&gt; #&amp;lt;Hash:{'a': 'kiwi', 'b': 'banana', 'c': 'coconut'}&amp;gt;

Object.inspect(obj);
// -&gt; [object Object]

obj.a = 'orange';
h.get('a');
// -&gt; 'apple'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-17:17988</id>
    <published>2007-11-17T15:22:00Z</published>
    <updated>2007-11-17T15:26:03Z</updated>
    <category term="Hash"/>
    <category term="1.6"/>
    <link href="http://www.prototypejs.org/api/hash/clone" rel="alternate" type="text/html"/>
    <title>clone</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;clone() -&gt; newHash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a clone of hash.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;clone() -&gt; newHash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a clone of hash.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ a: 'apple'});
var clone = h.clone();

h.unset('a');
h.inspect();
// -&gt; #&amp;lt;Hash:{}&amp;gt;

clone.inspect();
// -&gt; #&amp;lt;Hash:{'a': 'apple'}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-17:17987</id>
    <published>2007-11-17T14:48:00Z</published>
    <updated>2007-11-19T21:06:44Z</updated>
    <category term="Hash"/>
    <category term="1.6"/>
    <link href="http://www.prototypejs.org/api/hash/update" rel="alternate" type="text/html"/>
    <title>update</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;update(object) -&gt; Hash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Updates hash with the key/value pairs of &lt;code&gt;object&lt;/code&gt;. The original hash will be modified.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;update(object) -&gt; Hash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Updates hash with the key/value pairs of &lt;code&gt;object&lt;/code&gt;. The original hash will be modified.&lt;/p&gt;
&lt;p&gt;Duplicate keys will cause an overwrite of hash&#8217;s keys.  This is useful for selectively overwriting values on specific keys (e.g. exerting some level of control over a series of options).&lt;/p&gt;

&lt;p&gt;The argument can be a &lt;code&gt;Hash&lt;/code&gt; or just a vanilla &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = $H({ name: 'Prototype', version: 1.5 });

h.update({ version: 1.6, author: 'Sam' }).inspect();
// -&gt; #&amp;lt;Hash:{'name': 'Prototype', 'version': 1.6, 'author': 'Sam'}&amp;gt;

h.inspect();
// -&gt; #&amp;lt;Hash:{'name': 'Prototype', 'version': 1.6, 'author': 'Sam'}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;See also&lt;/h3&gt;

&lt;p&gt;If you need a &lt;em&gt;non-destructive&lt;/em&gt; merge, try &lt;a href=&quot;merge&quot;&gt;&lt;code&gt;Hash#merge&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-17:17986</id>
    <published>2007-11-17T14:19:00Z</published>
    <updated>2007-11-17T14:22:03Z</updated>
    <category term="Hash"/>
    <category term="1.6"/>
    <link href="http://www.prototypejs.org/api/hash/get" rel="alternate" type="text/html"/>
    <title>get</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;get(key) -&gt; value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the value of the hash&#8217;s &lt;code&gt;key&lt;/code&gt; property.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;get(key) -&gt; value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the value of the hash&#8217;s &lt;code&gt;key&lt;/code&gt; property.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ a: 'apple', b: 'banana', c: 'coconut' });

h.get('a');
// -&gt; 'apple'

h.get('d');
// -&gt; undefined
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-17:17985</id>
    <published>2007-11-17T14:13:00Z</published>
    <updated>2007-11-19T21:05:34Z</updated>
    <category term="Hash"/>
    <category term="1.6"/>
    <link href="http://www.prototypejs.org/api/hash/unset" rel="alternate" type="text/html"/>
    <title>unset</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;unset(key) -&gt; value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Deletes the hash&#8217;s &lt;code&gt;key&lt;/code&gt; property and returns its value.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;unset(key) -&gt; value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Deletes the hash&#8217;s &lt;code&gt;key&lt;/code&gt; property and returns its value.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ a: 'apple', b: 'banana', c: 'coconut' });

h.unset('a');
// -&gt; 'apple'
h.inspect();
// -&gt; #&amp;lt;Hash:{'b': 'banana', 'c': 'coconut'}&amp;gt;

h.unset('d');
// -&gt; undefined
h.inspect();
// -&gt; #&amp;lt;Hash:{'b': 'banana', 'c': 'coconut'}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-17:17984</id>
    <published>2007-11-17T14:01:00Z</published>
    <updated>2007-11-17T14:17:07Z</updated>
    <category term="Hash"/>
    <category term="1.6"/>
    <link href="http://www.prototypejs.org/api/hash/set" rel="alternate" type="text/html"/>
    <title>set</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;set(key, value) -&gt; value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sets the hash&#8217;s &lt;code&gt;key&lt;/code&gt; property to &lt;code&gt;value&lt;/code&gt; and returns &lt;code&gt;value&lt;/code&gt;.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;set(key, value) -&gt; value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sets the hash&#8217;s &lt;code&gt;key&lt;/code&gt; property to &lt;code&gt;value&lt;/code&gt; and returns &lt;code&gt;value&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ a: 'apple', b: 'banana', c: 'coconut' });

h.set('d', 'orange');
// -&gt; 'orange'
h.inspect();
// -&gt; #&amp;lt;Hash:{'a': 'apple', 'b': 'banana', 'c': 'coconut', 'd': 'orange'}&amp;gt;

h.set('a', 'kiwi');
// -&gt; 'kiwi'
h.inspect();
// -&gt; #&amp;lt;Hash:{'a': 'kiwi', 'b': 'banana', 'c': 'coconut', 'd': 'orange'}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-03-10:14773</id>
    <published>2007-03-10T00:54:00Z</published>
    <updated>2007-04-30T20:26:40Z</updated>
    <category term="Hash"/>
    <category term="1.5.1"/>
    <link href="http://www.prototypejs.org/api/hash/tojson" rel="alternate" type="text/html"/>
    <title>toJSON</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toJSON() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a JSON string.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toJSON() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a JSON string.&lt;/p&gt;
&lt;h3&gt;Example&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$H({name: 'Violet', occupation: 'character', age: 25 }).toJSON();
//-&gt; '{&quot;name&quot;: &quot;Violet&quot;, &quot;occupation&quot;: &quot;character&quot;, &quot;age&quot;: 25}'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Mislav</name>
    </author>
    <id>tag:www.prototypejs.org,2007-01-17:13077</id>
    <published>2007-01-17T10:12:00Z</published>
    <updated>2007-11-17T15:34:59Z</updated>
    <category term="Hash"/>
    <category term="deprecated"/>
    <link href="http://www.prototypejs.org/api/hash/remove" rel="alternate" type="text/html"/>
    <title>remove</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;remove(key) -&gt; value
remove(key1, key2...) -&gt; Array&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Removes keys from a hash and returns their values. &lt;em&gt;Not available since v1.6.0&lt;/em&gt;.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;remove(key) -&gt; value
remove(key1, key2...) -&gt; Array&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Removes keys from a hash and returns their values. &lt;em&gt;Not available since v1.6.0&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&quot;deprecated&quot;&gt;&lt;p&gt;This method is not available since Prototype 1.6.0. Use &lt;code&gt;Hash#unset()&lt;/code&gt; for removing a value from a Hash instance. For removing multiple values, use a loop:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;['foo', 'bar'].each(function(key) {
  hash.unset(key);
});
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ a:'apple', b:'banana', c:'coconut' })

h.remove('a', 'c')
// -&gt; ['apple', 'coconut']
h.values()
// -&gt; ['banana']
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Christophe</name>
    </author>
    <id>tag:www.prototypejs.org,2007-01-06:12979</id>
    <published>2007-01-06T15:53:00Z</published>
    <updated>2007-10-13T17:00:12Z</updated>
    <category term="Hash"/>
    <link href="http://www.prototypejs.org/api/hash/each" rel="alternate" type="text/html"/>
    <title>each</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;each(iterator) -&gt; Hash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Iterates over the name/value pairs in the hash.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;each(iterator) -&gt; Hash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Iterates over the name/value pairs in the hash.&lt;/p&gt;
&lt;p&gt;This is actually the &lt;a href=&quot;/api/enumerable/each&quot;&gt;&lt;code&gt;each&lt;/code&gt;&lt;/a&gt; method from the mixed-in &lt;a href=&quot;/api/enumerable&quot;&gt;&lt;code&gt;Enumerable&lt;/code&gt;&lt;/a&gt; module.  It is documented here to illustrate the structure of the passed first argument, and the order of iteration.&lt;/p&gt;

&lt;p&gt;Pairs are passed as the first argument of the iterator, in the form of objects with two properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;key&lt;/code&gt;, which is the key name as a &lt;code&gt;String&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;value&lt;/code&gt;, which is the corresponding value (and can, possibly, be &lt;code&gt;undefined&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p class=&quot;notice&quot;&gt;The order of iteration is browser-dependent, as it relies on the native &lt;code&gt;for ... in&lt;/code&gt; loop. Although most modern browsers exhibit &lt;em&gt;ordered&lt;/em&gt; behavior, this may not always be the case, so don't count on it in your scripts.&lt;/p&gt;

&lt;p&gt;It is possible to have function values in a hash, though the iteration skips over Hash and Enumerable methods (naturally). More precisely, it skips the properties found on the object's prototype.&lt;/p&gt;

&lt;h3&gt;Example&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var h = $H({ version: 1.5, author: 'Sam Stephenson' });

h.each(function(pair) {
  alert(pair.key + ' = &quot;' + pair.value + '&quot;');
});

// Alerts, in non-guaranteed order: 'version = &quot;1.5&quot;' and 'author = &quot;Sam Stephenson&quot;'&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Christophe</name>
    </author>
    <id>tag:www.prototypejs.org,2007-01-06:12978</id>
    <published>2007-01-06T15:38:00Z</published>
    <updated>2007-10-13T16:56:04Z</updated>
    <category term="Hash"/>
    <link href="http://www.prototypejs.org/api/hash/inspect" rel="alternate" type="text/html"/>
    <title>inspect</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;inspect() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the debug-oriented string representation of the hash.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;inspect() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the debug-oriented string representation of the hash.&lt;/p&gt;
&lt;p&gt;For more information on &lt;code&gt;inspect&lt;/code&gt; methods, see &lt;a href=&quot;/api/object/inspect&quot;&gt;&lt;code&gt;Object.inspect&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;$H({ name: 'Prototype', version: 1.5 }).inspect()
// -&gt; &quot;&amp;lt;#Hash:{name: 'Prototype', version: 1.5}&gt;&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Hashes and ordering&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Don&#8217;t&lt;/em&gt; compare Hash instances by their string representation returned by this method. Although rarely the case, a &lt;em&gt;consistent order&lt;/em&gt; of key-value pairs is &lt;em&gt;not guaranteed&lt;/em&gt; in JavaScript.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-01-02:12913</id>
    <published>2007-01-02T18:15:00Z</published>
    <updated>2007-11-17T14:54:01Z</updated>
    <category term="Hash"/>
    <category term="1.6 modified"/>
    <link href="http://www.prototypejs.org/api/hash/toQueryString" rel="alternate" type="text/html"/>
    <title>toQueryString</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toQueryString() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Turns a hash into its URL-encoded query string representation.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toQueryString() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Turns a hash into its URL-encoded query string representation.&lt;/p&gt;
&lt;p&gt;This is a form of serialization, and is mostly useful to provide complex parameter sets for stuff such as objects in the Ajax namespace (e.g. &lt;a href=&quot;/api/ajax/request&quot;&gt;&lt;code&gt;Ajax.Request&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Undefined-value pairs will be serialized as if empty-valued.  Array-valued pairs will get serialized with one name/value pair per array element.  All values get URI-encoded using JavaScript's native &lt;code&gt;encodeURIComponent&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;The order of pairs in the serialized form is not guaranteed (and mostly irrelevant anyway), except for array-based parts, which are serialized in array order.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;$H({ action: 'ship', order_id: 123, fees: ['f1', 'f2'], 'label': 'a demo' }).toQueryString()
// -&gt; 'action=ship&amp;order_id=123&amp;fees=f1&amp;fees=f2&amp;label=a%20demo'

// an empty hash is an empty query string:
$H().toQueryString()
// -&gt; ''&lt;/code&gt;&lt;/pre&gt;

&lt;p class=&quot;deprecated&quot;&gt;Using &lt;code&gt;Hash.toQueryString(obj)&lt;/code&gt; as a &lt;strong&gt;class method&lt;/strong&gt; has been deprecated. Use it as an instance method only, or use &lt;a href=&quot;/api/object/toquerystring&quot;&gt;&lt;code&gt;Object.toQueryString&lt;/code&gt;&lt;/a&gt; instead.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:www.prototypejs.org,2006-12-07:12788</id>
    <published>2006-12-07T20:30:00Z</published>
    <updated>2007-11-17T14:47:30Z</updated>
    <category term="Hash"/>
    <category term="1.6 modified"/>
    <link href="http://www.prototypejs.org/api/hash/merge" rel="alternate" type="text/html"/>
    <title>merge</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;merge(object) -&gt; newHash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Merges &lt;code&gt;object&lt;/code&gt; to hash and returns the result of that merge.
&lt;em&gt;Prior to v1.6.0:&lt;/em&gt; This was destructive (object's values were added to hash).
&lt;em&gt;Since v1.6.0:&lt;/em&gt; This is no longer destructive (hash is cloned before the operation).&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;merge(object) -&gt; newHash&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Merges &lt;code&gt;object&lt;/code&gt; to hash and returns the result of that merge.
&lt;em&gt;Prior to v1.6.0:&lt;/em&gt; This was destructive (object's values were added to hash).
&lt;em&gt;Since v1.6.0:&lt;/em&gt; This is no longer destructive (hash is cloned before the operation).&lt;/p&gt;
&lt;p&gt;Duplicate keys will cause an overwrite.  This is useful for selectively overwriting values on specific keys (e.g. exerting some level of control over a series of options).&lt;/p&gt;

&lt;p&gt;The argument can be a &lt;code&gt;Hash&lt;/code&gt; or just a vanilla &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;p&gt;As of 1.6.0 &lt;code&gt;Hash#merge&lt;/code&gt; returns a new hash:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = $H({ name: 'Prototype', version: 1.5 });

h.merge({ version: 1.6, author: 'Sam' }).inspect();
// -&gt; #&amp;lt;Hash:{'name': 'Prototype', 'version': 1.6, 'author': 'Sam'}&amp;gt;

h.inspect();
// -&gt; #&amp;lt;Hash:{'name': 'Prototype', 'version': 1.5}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Prior to 1.6.0 &lt;code&gt;Hash#merge&lt;/code&gt; was destructive:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = $H({ name: 'Prototype', version: 1.5 });

h.merge({ version: 1.6, author: 'Sam' }).inspect();
// -&gt; #&amp;lt;Hash:{'name': 'Prototype', 'version': 1.6, 'author': 'Sam'}&amp;gt;

h.inspect();
// -&gt; #&amp;lt;Hash:{'name': 'Prototype', 'version': 1.6, 'author': 'Sam'}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;See also&lt;/h3&gt;

&lt;p&gt;If you are using 1.6.0 or above and need a &lt;em&gt;destructive&lt;/em&gt; merge, try &lt;a href=&quot;update&quot;&gt;&lt;code&gt;Hash#update&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:www.prototypejs.org,2006-12-07:12787</id>
    <published>2006-12-07T20:24:00Z</published>
    <updated>2007-01-17T10:11:30Z</updated>
    <category term="Hash"/>
    <link href="http://www.prototypejs.org/api/hash/values" rel="alternate" type="text/html"/>
    <title>values</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;values() -&gt; Array&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Collect the values of a hash and returns them in an array.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;values() -&gt; Array&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Collect the values of a hash and returns them in an array.&lt;/p&gt;
&lt;p&gt;The order of values is browser implementation-dependent (based on the &lt;code&gt;for&lt;/code&gt;&#8230;&lt;code&gt;in&lt;/code&gt; loop on keys), so&amp;mdash;although most of the time you will see it as consistent&amp;mdash;it&#8217;s better not to rely on a specific order. Also remember that the hash may contain values such as &lt;code&gt;null&lt;/code&gt; or even &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$H({ name: 'Prototype', version: 1.5 }).values().sort()
// -&gt; [1.5, 'Prototype']

$H().values()
// -&gt; []
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:www.prototypejs.org,2006-12-07:12786</id>
    <published>2006-12-07T20:20:00Z</published>
    <updated>2007-01-06T15:48:39Z</updated>
    <category term="Hash"/>
    <link href="http://www.prototypejs.org/api/hash/keys" rel="alternate" type="text/html"/>
    <title>keys</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;keys() -&gt; [String...]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Provides an Array of keys (that is, property names) for the hash.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;keys() -&gt; [String...]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Provides an Array of keys (that is, property names) for the hash.&lt;/p&gt;
&lt;p&gt;Note: the order of key names is browser-dependent (based on the &lt;code&gt;for&lt;/code&gt;&#8230;&lt;code&gt;in&lt;/code&gt; loop). Also, this currently skips any property whose value is a function (such as hash methods).&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$H({ name: 'Prototype', version: 1.5 }).keys().sort()
// -&gt; ['name', 'version']

$H().keys()
// -&gt; []
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:www.prototypejs.org,2006-12-05:12750</id>
    <published>2006-12-05T21:47:00Z</published>
    <updated>2007-11-17T15:20:55Z</updated>
    <category term="Hash"/>
    <link href="http://www.prototypejs.org/api/hash" rel="alternate" type="text/html"/>
    <title>Hash</title>
<content type="html">
            &lt;p&gt;Hash can be thought of as an &lt;em&gt;associative array&lt;/em&gt;, binding unique keys to values (which are not necessarily unique), though it can not guarantee consistent order its elements when iterating. Because of the nature of JavaScript programming language, every object is in fact a hash; but &lt;code&gt;Hash&lt;/code&gt; adds a number of methods that let you enumerate keys and values, iterate over key/value pairs, merge two hashes together, encode the hash into a query string representation, etc.&lt;/p&gt;

&lt;h3&gt;Creating a hash&lt;/h3&gt;

&lt;p&gt;There are two ways to construct a &lt;code&gt;Hash&lt;/code&gt; instance: the first is regular JavaScript object instantiation with the &lt;code&gt;new&lt;/code&gt; keyword, and the second is using the &lt;a href=&quot;/api/utility/dollar-h&quot;&gt;&lt;code&gt;$H&lt;/code&gt;&lt;/a&gt; function. Passing a plain JavaScript object or a Hash to any of them would clone it, keeping your original object intact.&lt;/p&gt;

&lt;p&gt;You can call both constructor methods without arguments, too; they will assume an empty hash.&lt;/p&gt;

&lt;h3&gt;Backwards compatibility changes in Prototype 1.6&lt;/h3&gt;

&lt;p class=&quot;notice&quot;&gt; &lt;strong&gt;Backwards compatibility change&lt;/strong&gt; - Although it serves the same purpose as before, the new version of Hash is &lt;strong&gt;not&lt;/strong&gt; compatible with the Hash class in previous versions of Prototype.&lt;/p&gt;

&lt;p&gt;Hash properties are now hidden away in a private store to prevent the risk of collision with Hash&#8217;s instance and mixed-in methods. This means that properties of the hash can no longer be set, accessed or deleted directly; you must use the &lt;a href=&quot;/api/hash/get&quot;&gt;&lt;code&gt;Hash#get(key)&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;/api/hash/set&quot;&gt;&lt;code&gt;Hash#set(key, value)&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;/api/hash/unset&quot;&gt;&lt;code&gt;Hash#unset(key)&lt;/code&gt;&lt;/a&gt; instance methods instead. To illustrate:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var myhash = new Hash();

// old API  --&gt;  new API
myhash.name = &quot;Bob&quot;;  --&gt;  myhash.set('name', 'Bob');
myhash.name;          --&gt;  myhash.get('name');
delete myhash.name;   --&gt;  myhash.unset('name');&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should also be aware of other changes to the Hash API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The $H(object) shortcut is now completely equivalent to new Hash(object). Both always return a new object, regardless of whether the argument was an Object or another Hash.&lt;/li&gt;
&lt;li&gt;Hash#merge returns a new Hash instead of modifying the Hash it&#8217;s called on.&lt;/li&gt;
&lt;li&gt;Hash#update is a destructive version of Hash#merge that modifies the Hash it&#8217;s called on.&lt;/li&gt;
&lt;li&gt;Hash#clone returns a new, cloned instance of Hash.&lt;/li&gt;
&lt;li&gt;Hash#toObject that returns a copy of the Hash&#8217;s inner Object.&lt;/li&gt;
&lt;li&gt;Hash.toQueryString is now an alias of Object.toQueryString.  (Hash.toQueryString is deprecated and will be removed in a future version of Prototype.)&lt;/li&gt;
&lt;li&gt;Hash#remove has been removed in favor of Hash#unset.&lt;/li&gt;
&lt;li&gt;Hash.toJSON has been removed in favor of Object.toJSON or the Hash#toJSON instance method.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Notes for earlier versions of Prototype (&amp;lt; 1.6)&lt;/h3&gt;

&lt;p&gt;Passing a hash to $H did not clone it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hash&lt;/code&gt; could not hold &lt;em&gt;any&lt;/em&gt; key because of having Enumerable mixed in, as well as its own methods. After adding a key that had the same name as any of those methods, this method would no longer be callable. You could get away with doing that to methods you didn&#8217;t need, but there were still issues:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var h = new Hash({ ... });
h['each'] = 'my own stuff';
h.map();
// -&gt; errors out because 'each' is not a function
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The most important method in Enumerable is &lt;a href=&quot;/api/enumerable/each&quot;&gt;&#8216;each&#8217;&lt;/a&gt;, and&amp;mdash;since almost every other method uses it&amp;mdash;overwriting it renders our hash instance practically useless. You couldn&#8217;t get away with using &#8216;_each&#8217;, too, since it also is an internal Enumerable method.&lt;/p&gt;
          </content>  </entry>
</feed>
