-
-
Save tommcfarlin/f49bf5f79fe4e0f2ba2d to your computer and use it in GitHub Desktop.
[JavaScript] A few examples of how using named functions can be more useful than anonymous functions.
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
$( '#button' ).on( 'click', function() { | |
// Do work | |
}); |
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
function myHandler() { | |
// Do work | |
} | |
$( '#button' ).on( 'click', myHandler ); |
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
(function($) { | |
'use strict'; | |
$(function() { | |
toggleSocialIconVisibility( $, '#email-address', 'mayer_email_address' ); | |
toggleSocialIconVisibility( $, '#twitter', 'mayer_twitter_username' ); | |
toggleSocialIconVisibility( $, '#facebook', 'mayer_facebook_url' ); | |
toggleSocialIconVisibility( $, '#pinterest', 'mayer_pinterest_url' ); | |
toggleSocialIconVisibility( $, '#google-plus', 'mayer_googleplus_url' ); | |
toggleSocialIconVisibility( $, '#linkedin', 'mayer_linkedin_url' ); | |
toggleGravatarVisibility( $, '#avatar', 'mayer_display_gravatar' ); | |
toggleFooterSocialIcons( $, '#social-icons-wrapper', 'mayer_display_footer_social_icons' ); | |
}); | |
})( jQuery ); |
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
function setupControls( $ ) { | |
toggleSocialIconVisibility( $, '#email-address', 'mayer_email_address' ); | |
toggleSocialIconVisibility( $, '#twitter', 'mayer_twitter_username' ); | |
toggleSocialIconVisibility( $, '#facebook', 'mayer_facebook_url' ); | |
toggleSocialIconVisibility( $, '#pinterest', 'mayer_pinterest_url' ); | |
toggleSocialIconVisibility( $, '#google-plus', 'mayer_googleplus_url' ); | |
toggleSocialIconVisibility( $, '#linkedin', 'mayer_linkedin_url' ); | |
toggleGravatarVisibility( $, '#avatar', 'mayer_display_gravatar' ); | |
toggleFooterSocialIcons( $, '#social-icons-wrapper', 'mayer_display_footer_social_icons' ); | |
} | |
(function($) { | |
'use strict'; | |
$(function() { | |
setupControls( $ ); | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment