Created
April 27, 2015 16:42
-
-
Save sagiavinash/b960b73fd1d9ea904ecd 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 = 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