title: Stop function execution in javascript/jquery
body: <p>Is it possible to stop the execution of a function in javascript on click of a button or any other event for that matter? Following is my dilemma</p>
  
  <pre><code>function drop() {
  
      setTimeout(function () {    //  call a 250ms setTimeout when the loop is called
         setMarkers(map, locationArray, locationNameArray, iterator);
         iterator++;
         if (iterator &lt; locationArray.length) {      //  if the counter &lt; 10, loop!
           drop();             
         }
       }, 250);
  }
  </code></pre>
  
  <p>This function drops Google maps pins on my canvas at an interval of 250ms. Now if the user wants to navigate to the previous screen (away from the Map page), on click of the back button I want to stop the execution of this drop() function, reset the counter (iterator) and go back.</p>
  
  <p>Any idea how I can do this or if its even possible?
  Thanks!</p>