index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. if (!process.version ||
  3. process.version.indexOf('v0.') === 0 ||
  4. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  5. module.exports = { nextTick: nextTick };
  6. } else {
  7. module.exports = process
  8. }
  9. function nextTick(fn, arg1, arg2, arg3) {
  10. if (typeof fn !== 'function') {
  11. throw new TypeError('"callback" argument must be a function');
  12. }
  13. var len = arguments.length;
  14. var args, i;
  15. switch (len) {
  16. case 0:
  17. case 1:
  18. return process.nextTick(fn);
  19. case 2:
  20. return process.nextTick(function afterTickOne() {
  21. fn.call(null, arg1);
  22. });
  23. case 3:
  24. return process.nextTick(function afterTickTwo() {
  25. fn.call(null, arg1, arg2);
  26. });
  27. case 4:
  28. return process.nextTick(function afterTickThree() {
  29. fn.call(null, arg1, arg2, arg3);
  30. });
  31. default:
  32. args = new Array(len - 1);
  33. i = 0;
  34. while (i < args.length) {
  35. args[i++] = arguments[i];
  36. }
  37. return process.nextTick(function afterTick() {
  38. fn.apply(null, args);
  39. });
  40. }
  41. }