Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
Created July 22, 2014 22:16
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 alexkingorg/e8c5f5abad59f96eb837 to your computer and use it in GitHub Desktop.
Save alexkingorg/e8c5f5abad59f96eb837 to your computer and use it in GitHub Desktop.
JS micro-optimization?
// readable and easily re-orderable
$(document).on('submit', '#foo', myCallback1);
$(document).on('submit', '#bar', myCallback2);
$(document).on('click', '.baz', myCallback3);
// performant
$(document).on('submit', '#foo', myCallback1)
.on('submit', '#bar', myCallback2)
.on('click', '.baz', myCallback3);
// also performant
$document = $(document);
$document.on('submit', '#foo', myCallback1);
$document.on('submit', '#bar', myCallback2);
$document.on('click', '.baz', myCallback3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment