Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.