Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/f49bf5f79fe4e0f2ba2d to your computer and use it in GitHub Desktop.
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.
$( '#button' ).on( 'click', function() {
// Do work
});
function myHandler() {
// Do work
}
$( '#button' ).on( 'click', myHandler );
(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 );
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