JAVASCRIPT   18

web timers js

Guest on 26th June 2022 03:44:12 AM

  1. var $ = require('../internals/export');
  2. var global = require('../internals/global');
  3. var userAgent = require('../internals/user-agent');
  4.  
  5. var slice = [].slice;
  6. var MSIE = /MSIE .\./.test(userAgent); // <- dirty ie9- check
  7.  
  8. var wrap = function (scheduler) {
  9.   return function (handler, timeout /* , ...arguments */) {
  10.     var boundArgs = arguments.length > 2;
  11.     var args = boundArgs ? slice.call(arguments, 2) : undefined;
  12.     return scheduler(boundArgs ? function () {
  13.       // eslint-disable-next-line no-new-func
  14.       (typeof handler == 'function' ? handler : Function(handler)).apply(this, args);
  15.     } : handler, timeout);
  16.   };
  17. };
  18.  
  19. // ie9- setTimeout & setInterval additional parameters fix
  20. $({ global: true, bind: true, forced: MSIE }, {
  21.   // `setTimeout` method
  22.   // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout
  23.   setTimeout: wrap(global.setTimeout),
  24.   // `setInterval` method
  25.   setInterval: wrap(global.setInterval)
  26. });

Raw Paste


Login or Register to edit or fork this paste. It's free.