Hash.js

Contains the class Hash.

License

MIT-style license.

Summary
Hash.jsContains the class Hash.
HashIt wraps an object that it uses internally as a map.
Properties
getRetrieves a value from the hash.
hasKeyCheck the presence of a specified key-value pair in the hash.
setAdds a key-value pair to the hash or replaces a previous value associated with the key.
removeRemoves a key-value pair from the hash.
eachCalls a function for each key-value pair.
extendExtends the current hash with an object containing key-value pairs.
mergeMerges the current hash with multiple objects.
emptyEmpties all hash values properties and values.
keysReturns an array containing all the keys, in the same order as the values returned by Hash.values.
valuesReturns an array containing all the values, in the same order as the keys returned by Hash.keys.
Utility Functions
Functions
$HShortcut to create a Hash from an Object.

Hash

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.

Note

Each hash instance has the length property.

Arguments

objan object to convert into a Hash instance.

Example

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)
Summary
Properties
getRetrieves a value from the hash.
hasKeyCheck the presence of a specified key-value pair in the hash.
setAdds a key-value pair to the hash or replaces a previous value associated with the key.
removeRemoves a key-value pair from the hash.
eachCalls a function for each key-value pair.
extendExtends the current hash with an object containing key-value pairs.
mergeMerges the current hash with multiple objects.
emptyEmpties all hash values properties and values.
keysReturns an array containing all the keys, in the same order as the values returned by Hash.values.
valuesReturns an array containing all the values, in the same order as the keys returned by Hash.keys.

Properties

get

Retrieves a value from the hash.

Arguments

keyThe key

Returns

The value

hasKey

Check the presence of a specified key-value pair in the hash.

Arguments

keyThe key

Returns

True if the Hash contains a value for the specified key, otherwise false

set

Adds a key-value pair to the hash or replaces a previous value associated with the key.

Arguments

keyThe key
valueThe value

remove

Removes a key-value pair from the hash.

Arguments

keyThe key

each

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.

Arguments

fnThe function to call for each key-value pair
bindOptional, the object that will be referred to as “this” in the function

extend

Extends the current hash with an object containing key-value pairs.  Values for duplicate keys will be replaced by the new ones.

Arguments

objAn 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.

Returns

An array containing all the keys of the hash

values

Returns an array containing all the values, in the same order as the keys returned by Hash.keys.

Returns

An array containing all the values of the hash

Utility Functions

Summary
Functions
$HShortcut to create a Hash from an Object.

Functions

$H

Shortcut to create a Hash from an Object.

Returns an array containing all the values, in the same order as the keys returned by Hash.keys.
Returns an array containing all the keys, in the same order as the values returned by Hash.values.
Shortcut to create a Hash from an Object.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi