title: Static javascript variable to be used as counter in Angularjs controller
body: <p>I would like to create a static javascript variable to be used as a counter inside a Angularjs controller. This static variable will be used inside a polling function that gets repeatedly called.</p>
  
  <p>I want to use the static variable in a manner that looks like this;</p>
  
  <pre><code>var polling_func = function()
  {
      static var counter = 0;
  
      if (counter == 10)
      {
          alert('Do action');
          counter = 0;
      }
      counter = counter + 1;
      $timeout(polling_func, 1000);
  }
  polling_func();
  </code></pre>
  
  <p>Unfortunately, I cannot declare a static variable using static keyword in javascript. How should I go about doing so in my code?</p>