Keep Things DRY

jQuery

Keep Things DRY

Don't repeat yourself; if you're repeating yourself, you're doing it wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
                          
// 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();
}
});