Created
July 9, 2017 22:46
-
-
Save JoaoCnh/919a3cf584ef00204d68c1dc38843083 to your computer and use it in GitHub Desktop.
caching jQuery lookups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bad | |
function setSidebar() { | |
$('.sidebar').hide(); | |
// ... | |
$('.sidebar').css({ | |
'background-color': 'pink', | |
}); | |
} | |
// good | |
function setSidebar() { | |
const $sidebar = $('.sidebar'); | |
$sidebar.hide(); | |
// ... | |
$sidebar.css({ | |
'background-color': 'pink', | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment