Created
April 28, 2015 17:21
-
-
Save sagiavinash/2263072f8fb712cfc258 to your computer and use it in GitHub Desktop.
Function Properties (instead of global variables to store invokation values).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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