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