title: JavaScript addEventListener delay
body: <p>I'm building a mobile application using JavaScript. Into it i need to obtain data from phones' accelerometer, so I attach an event listener to it:</p>
  
  <pre><code>if (window.DeviceOrientationEvent) {
      window.addEventListener("deviceorientation", function (event) {
          if (typeof(event.alpha) != 'undefined') {
              //here goes function for an event
          }
      }, false);
  }
  </code></pre>
  
  <p>But the problem is that it obtains data every millisecond, thus when i call the function to draw and redraw something according to this data, it keeps doing it each millisecond -> application crashes.</p>
  
  <p>Is there any way to delay, or to receive this data in a smaller portions? Is there a function to listen to an event, for example, each half a second?</p>