the compact javascript framework
in partnership with mediatemple
Contains the class Hash.
MIT-style license.
Hash.js | Contains the class Hash. |
Hash | It wraps an object that it uses internally as a map. |
Properties | |
get | Retrieves a value from the hash. |
hasKey | Check the presence of a specified key-value pair in the hash. |
set | Adds a key-value pair to the hash or replaces a previous value associated with the key. |
remove | Removes a key-value pair from the hash. |
each | Calls a function for each key-value pair. |
extend | Extends the current hash with an object containing key-value pairs. |
merge | Merges the current hash with multiple objects. |
empty | Empties all hash values properties and values. |
keys | Returns an array containing all the keys, in the same order as the values returned by Hash.values. |
values | Returns an array containing all the values, in the same order as the keys returned by Hash.keys. |
Utility Functions | |
Functions | |
$H | Shortcut to create a Hash from an Object. |
It wraps an object that it uses internally as a map. The user must use set(), get(), and remove() to add/change, retrieve and remove values, it must not access the internal object directly. null/undefined values are allowed.
Each hash instance has the length property.
obj | an object to convert into a Hash instance. |
var hash = new Hash({a: 'hi', b: 'world', c: 'howdy'}); hash.remove('b'); // b is removed. hash.set('c', 'hello'); hash.get('c'); // returns 'hello' hash.length // returns 2 (a and c)
Properties | |
get | Retrieves a value from the hash. |
hasKey | Check the presence of a specified key-value pair in the hash. |
set | Adds a key-value pair to the hash or replaces a previous value associated with the key. |
remove | Removes a key-value pair from the hash. |
each | Calls a function for each key-value pair. |
extend | Extends the current hash with an object containing key-value pairs. |
merge | Merges the current hash with multiple objects. |
empty | Empties all hash values properties and values. |
keys | Returns an array containing all the keys, in the same order as the values returned by Hash.values. |
values | Returns an array containing all the values, in the same order as the keys returned by Hash.keys. |
Check the presence of a specified key-value pair in the hash.
key | The key |
True if the Hash contains a value for the specified key, otherwise false
Adds a key-value pair to the hash or replaces a previous value associated with the key.
key | The key |
value | The value |
Calls a function for each key-value pair. The first argument passed to the function will be the value, the second one will be the key, like $each.
fn | The function to call for each key-value pair |
bind | Optional, the object that will be referred to as “this” in the function |
Extends the current hash with an object containing key-value pairs. Values for duplicate keys will be replaced by the new ones.
obj | An object containing key-value pairs |
Returns an array containing all the keys, in the same order as the values returned by Hash.values.
An array containing all the keys of the hash
Returns an array containing all the values, in the same order as the keys returned by Hash.keys.
An array containing all the values of the hash
Shortcut to create a Hash from an Object.
Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi