function throttleLeadingAndTrailing(functionToThrottle, minimumInterval, optionalContext) {
  var lastTime;
  var deferTimer;
  if (optionalContext) {
    functionToThrottle = functionToThrottle.bind(optionalContext);
  }
  var args;
  var timerExpired = function () {
    // Reached end of interval, call function
    lastTime = Date.now();
    functionToThrottle.apply(this, args);
    deferTimer = undefined;
  };
  return function () {
    var time = Date.now();
    var sinceLastTime = typeof lastTime === 'undefined' ? minimumInterval : time - lastTime;
    if (sinceLastTime >= minimumInterval) {
      // Outside of minimum interval, call throttled function.
      // Clear any pending timer as timeout imprecisions could otherwise cause two calls
      // for the same interval.
      clearTimeout(deferTimer);
      deferTimer = undefined;
      lastTime = time;
      functionToThrottle.apply(null, arguments);
    } else {
      // Inside minimum interval, create timer if needed.
      deferTimer = deferTimer || setTimeout(timerExpired, minimumInterval - sinceLastTime);
      // Update args for when timer expires.
      args = arguments;
    }
  };
}
Returns throttle function that gets called at most once every interval.
If there are multiple calls in the last interval we call the function one additional
time.
It behaves like throttle except for the very last call that gets deferred until the end of the interval.
This is useful when an event is used to trigger synchronization of state, and there is a need to converge
to the correct final state following a burst of events.

Example use cases:
- synchronizing state based on the componentchanged event
- following a mouse pointer using the mousemove event
- integrating with THREE.TransformControls, via the objectChange event.

@param {function} functionToThrottle
@param {number} minimumInterval - Minimal interval between calls (milliseconds).
@param {object} optionalContext - If given, bind function to throttle to this context.
@returns {function} Throttled function.