Skip to content

Instantly share code, notes, and snippets.

@sagiavinash
Created April 28, 2015 17:21
Show Gist options
  • Save sagiavinash/2263072f8fb712cfc258 to your computer and use it in GitHub Desktop.
Save sagiavinash/2263072f8fb712cfc258 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 = ("counter" in handler) ? 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