相关疑难解决方法(0)

如果多次使用它,我应该在jQuery中缓存$(this)吗?

我知道如果您多次使用它,您应该缓存选择器的结果.一个例子是:

var $selected = $('.some-selected-element');

process($selected);
doStuff($selected);
Run Code Online (Sandbox Code Playgroud)

$(this)如果多次使用缓存,是否有任何性能优势?

$('.some-selector').hover(function () {
    if (!$(this).hasClass('some-other-class')) {
        $(this).addClass('another-class');
    }
    process($(this));
}
Run Code Online (Sandbox Code Playgroud)

performance jquery jquery-selectors

6
推荐指数
1
解决办法
1090
查看次数

标签 统计

jquery ×1

jquery-selectors ×1

performance ×1