title: setInterval triggers function multiple times
body: <p>EDIT: what i mean by fires multiple times, is that newjob() will fire 3 times, every 5 seconds...so in 20 seconds i'll have it 12 times triggered, instead of the 4 times that i would want. so it's triggeres multiple times every 5 seconds, instead of once every 5 seconds.</p>
  
  <p>I have a function that i created using Toastr to display a message on my web application. i'm eventually going to tie it to an ajax request to an API to determine whether or not to display a message, but for now i'm just testing how it looks.</p>
  
  <p>i am setting an interval, but it fires the function inside of it multiple times (usually 3).</p>
  
  <pre><code>$(document).ready(function() {
      setInterval(function () {
          newJob();
      }, 5000);
  });
  </code></pre>
  
  <p>i can't do setInterval( function(e) { } as e is undefined, as there is no event associated with it, on click, i've used e.stopImmediatePropagation(); to have it only fire once.
  how can i stop this immediate propagation on set interval if i don't have e?</p>
  
  <p>thank you.</p>
  
  <p>EDIT: full code:</p>
  
  <pre><code>var newJob = function(e) {
      var i = -1;
      var $toastlast;
  
      var getMessage = function () {
          var msgs = ["There's a new job in the job dispatch queue", "A job pending approval has timed out"];
          i++;
          if (i === msgs.length) {
              i = 0;
          }
  
          return msgs[i];
      };
  
      var shortCutFunction = "success"; // 'success' or 'error'
  
      toastr.options = {
          closeButton: true,
          progressBar: true,
          debug: false,
          positionClass: 'toast-top-full-width',
          onclick: null,
          timeOut: "0",
          extendedTimeOut: "0",
          showDuration: "0",
          hideDuration: "0",
          showEasing: "swing",
          hideEasing: "linear",
          showMethod: "fadeIn",
          hideMethod: "fadeOut",
      };
  
  
      toastr.options.onclick = function () {
          window.location.href = "/dispatcher";
      };
  
      var msg = getMessage();
  
      $("#toastrOptions").text("Command: toastr["
                      + shortCutFunction
                      + "](\""
                      + msg
                      + "\")\n\ntoastr.options = "
                      + JSON.stringify(toastr.options, null, 2)
      );
  
      var $toast = toastr[shortCutFunction](msg);
  
  };
  
  $(document).ready(function() {
      setInterval(function () {
          console.log('set interval');
          newJob();
      }, 5000);
  
  
  });
  </code></pre>
  
  <p>and this is my index.phtml file:</p>
  
  <pre><code>    &lt;?php
  echo $this-&gt;headScript()-&gt;appendFile($this-&gt;basePath() . '/plugins/toastr/toastr.js')
  echo $this-&gt;headScript()-&gt;appendFile($this-&gt;basePath().'/js/dispatchernotification.js');
      ?&gt;
  </code></pre>
  
  <p>all i'm doing is adding the javascript of what i want running to my index.phtml file and the toastr library.
  by console.loging inside interval, i get three logs.</p>
  
  <p>here's a fiddle..not sure how to run it though as it's on ready
  <a href="http://jsfiddle.net/efecarranza/rfvbhr1o/" rel="nofollow">http://jsfiddle.net/efecarranza/rfvbhr1o/</a></p>