later = function() {
          var last = (new Date()) - timestamp;
          if (last < wait) {
            timeout = setTimeout(later, wait - last);
          } else {
            timeout = null;
            if (!immediate) result = func.apply(context, args);
          }
        }
Only call a function once in the given interval.

@param func {Function} the function to call
@param wait {int} how long to wait before/after to allow function calls
@param immediate {boolean} whether to call immediately or after the wait interval