My question has to do with optimizing my javascript code to be more efficient.
I have a function that is called frequently but all the code inside is only needed to be called once, like so:
function removeBlankCanvas() {
if ( --numberOfChartsStillLoading == 0 ) {
//do stuff
}
}
This works fine but the function is still called countless times after numberOfChartsStillLoading is 0, and I know it will never be 0 again. So I'm thinking about doing something like this:
function removeBlankCanvas() {
if ( --numberOfChartsStillLoading == 0 ) {
//do stuff
removeBlankCanvas = function() {
return true;
}
}
}
Could this be more efficient code? For instance, if the function was called millions of times? I'm asking strictly for curiosity's sake.