26. jQuery
26.1 Prefix jQuery object variables with a $.
const sidebar = $('.sidebar');
const $sidebar = $('.sidebar');
const $sidebarBtn = $('.sidebar-btn');
26.2 Cache jQuery lookups.
function setSidebar() {
$('.sidebar').hide();
$('.sidebar').css({
'background-color': 'pink',
});
}
function setSidebar() {
const $sidebar = $('.sidebar');
$sidebar.hide();
$sidebar.css({
'background-color': 'pink',
});
}
26.4 Use find with scoped jQuery object queries.
$('ul', '.sidebar').hide();
$('.sidebar').find('ul').hide();
$('.sidebar ul').hide();
$('.sidebar > ul').hide();
$sidebar.find('ul').hide();
출처 : https://github.com/airbnb/javascript