MooTools "Nine"-tool class hash and color

Source: Internet
Author: User
Tags empty hash mootools

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})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.