$H :: Utility Methods

$H([obj]) -> EnumerableHash The only way to obtain a hash (which is synonymous to “map” or “associative array” for our purposes). Returns a new object featuring all the methods in the Hash and Enumerable modules. If an original object was passed, clones all its properties in the result before mixing in the modules.

The $H function is the only proper way to obtain a hash.

Indeed, Hash is a module, not a class participating in Prototype’s class mechanism: doing a new Hash() is not going to help much: it will raise a ”Hash is not a constructor” error.

The Hash module is designed to be mixed into objects that also mix in Enumerable, so the $H function makes sure it provides you with a result object that mixes in both of those.

You can call $H() without any argument: you’ll obtain an “empty” hash (one that only features the methods in the mixed-in modules). If you pass it an argument, it starts by cloning out the passed object before mixing the modules in. Any property from that object whose name conflicts with a method in the modules will therefore get erased.

There currently is a pending patch by our beloved Mislav, which provides “safe hashes,” i.e. hashes that can use any key name, without any risk of conflict or syntactic limitation. This page will get updated when/if this issue evolves.

Prototype API 1.5.0 - prototypejs.org