Debian Codegraph @

timers-ext/delay.js

raw
1 "use strict";
2
3 var callable = require("es5-ext/object/valid-callable")
4 , nextTick = require("next-tick")
5 , validTimeout = require("./valid-timeout");
6
7 var apply = Function.prototype.apply;
8
9 module.exports = function (fn/*, timeout*/) {
10 var delay, timeout = arguments[1];
11 callable(fn);
12 if (timeout === undefined) {
13 delay = nextTick;
14 } else {
15 timeout = validTimeout(timeout);
16 delay = setTimeout;
17 }
18 return function () { return delay(apply.bind(fn, this, arguments), timeout); };
19 };