Description: Hash data structure, we are usually used to store key value pairs. In JavaScript, there is no specification of the hash implementation, in general, we will be wrapped object to simulate the implementation of such a hash, to achieve the normalized hash object operation.
In addition, the operation of color code in the UI is very frequent, especially to do a very gorgeous effect, you need to do a lot of color code calculation, MooTools in this regard do a relatively much work, through the extension of the String,array, as well as the provision of color classes, We can convert and compute the color data at any time.
1. Class: Hash
Construct Method-Pass in an object containing the key value pair
Method:
Get: Key Fetch value
Haskey: Determines whether the specified key is available
Set: Store key value pairs into hash
Remove: Deletes the key value pair for the specified key
Each: The usage is similar to each of the array, with the function specified in each of the key-value pairs through each
The first parameter (value) and the second argument (key) are passed in.
Extend: Merges an object containing a key-value pair into the current hash, and the value of the same key is overwritten by the new value.
Empty: The functionality of this method is completely different in the mootools1.0 and 1.1dev versions,
1.0 is to determine whether the hash has no key value pairs, while in the 1.1dev is empty the hash of all the key value pairs, please note the difference.
Keys: Getting all the keys in the hash
Values: Get all the values in the hash
Example:
var hash = new Hash ({
One:1,
Two:2,
Three:3
});
var one = Hash.get (' one ');
var hk = Hash.haskey (' three ');
Hash.set (' Four ', 4);
Hash.each (function (v,k) {
Alert (k + '-' +v);
});
Other:
Quick way to create a hash:
$H
$H({a:1,b:2})