Показаны сообщения с ярлыком js. Показать все сообщения
Показаны сообщения с ярлыком js. Показать все сообщения

четверг, 10 января 2013 г.

Effective Mootools usage tips | Cоветы эффективного использования Mootools

  • Never use the search by selector, beginning with the class:
    $$('.class some other selectors')
    The search results that will select all elements in the document, and then some of them will be filtered. If you add a name tag at the beginning, then the document will be selected only those elements, the name tag of the specified. Performance gains can be tens of times for large documents! Sample code:
    console.time("fast");
    console.log($$('div.tabmenu-icon').length);
    console.timeEnd("fast");
    
    console.time("slow");
    console.log($$('.tabmenu-icon').length);
    console.timeEnd("slow");
    
    console.time("all");
    console.log($$('*').length); // count all elements on page
    console.timeEnd("all");
    Output:
    164
    fast: 5ms
    164
    slow: 13ms
    3991
    all: 9ms