Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Created March 30, 2021 08:27
Show Gist options
  • Save LeanSeverino1022/667e436a3af1c700966d13c6d1075e5c to your computer and use it in GitHub Desktop.
Save LeanSeverino1022/667e436a3af1c700966d13c6d1075e5c to your computer and use it in GitHub Desktop.
multiples ifs to each (DRY) #designPatterns
// BAD
if ( eventfade.data( "currently" ) !== "showing" ) {
eventfade.stop();
}
if ( eventhover.data( "currently" ) !== "showing" ) {
eventhover.stop();
}
if ( spans.data( "currently" ) !== "showing" ) {
spans.stop();
}
// GOOD!!
var elems = [ eventfade, eventhover, spans ];
$.each( elems, function( i, elem ) {
if ( elem.data( "currently" ) !== "showing" ) {
elem.stop();
}
});
//src: https://learn.jquery.com/code-organization/dont-repeat-yourself/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment