Created
March 30, 2021 08:27
-
-
Save LeanSeverino1022/667e436a3af1c700966d13c6d1075e5c to your computer and use it in GitHub Desktop.
multiples ifs to each (DRY) #designPatterns
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 | |
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