Skip to content

Instantly share code, notes, and snippets.

@sagiavinash
Created April 27, 2015 16:42
Show Gist options
  • Save sagiavinash/b960b73fd1d9ea904ecd to your computer and use it in GitHub Desktop.
Save sagiavinash/b960b73fd1d9ea904ecd to your computer and use it in GitHub Desktop.
Function Properties (instead of global variables to store invokation values).
/*
instead of declaring global variables.
var counter = 0;
$(document).on("click", function(){
console.log(counter);
counter++;
});
*/
$(document).on("click", function handler(){
handler.counter = handler.hasOwnProperty("counter") ? handler.counter : 0;
console.log(handler.counter);
handler.counter++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment