简体   繁体   中英

What is the meaning of $H in Javascript/JQuery?

This jsfiddle.net example includes $H :

new Request.JSON({
    url: '/echo/json/',
    data: {
        json: JSON.encode({
            text: 'some text',
            array: [1, 2, 'three'],
            object: {
                par1: 'another text',
                par2: [3, 2, 'one'],
                par3: {}
            }
        }),
        delay: 3
    },
    onSuccess: function(response) {
        show_response(response, $('post'));
    }
}).send();

show_response = function(obj, result) {
    $H(obj).each(function(v, k) {
        new Element('li', {
            text: k + ': ' + v
        }).inject(result);
    });
    result.highlight();
};

I can't seem to find the meaning/function of $H. Can someone elaborate?

$H is to do with mootools, not jQuery. You find the doc here (pg 67). Excerpt below:

$H is a shortcut to initialize an instance of Hash . Usage :
$H(object) Example : var fooHash = $H({foo: 'bar'}); When you'll use it : This is just a shortcut for new Hash(obj) , which returns an instance of Hash

$H is just a function, defined by one of the other scripts in (or linked in from) the page. JS identifiers can contain $; it's just used because it looks special (and mortals are so used to the "only word chars" rules for identifiers, that it's unlikely to conflict with other people's stuff).

Look through the other scripts for a function named $H, or for some code that copies/moves $ (a very common name in frameworks, and thus, likely to conflict) to something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM