1 该插件封装了原生的定时器的方法

插件npm链接

2 项目中使用该插件的原因

主要是在react项目中,在自定义的组件上使用了mobox,设置了observer之后,该组件调用的setTimeout等方法,并非windows对象原生的方法,而是native function,所以import了该插件中的相关方法,从而实现原生的定时器功能
复制代码

3 相关源码

var scope = (typeof global !== "undefined" && global) ||(typeof self !== "undefined" && self) ||window;
var apply = Function.prototype.apply;// DOM APIs, for completenessexports.setTimeout = function() {return new Timeout(apply.call(setTimeout, scope, arguments), clearTimeout);
};
exports.setInterval = function() {return new Timeout(apply.call(setInterval, scope, arguments), clearInterval);
};
exports.clearTimeout =
exports.clearInterval = function(timeout) {if (timeout) {timeout.close();}
};function Timeout(id, clearFn) {this._id = id;this._clearFn = clearFn;
}
Timeout.prototype.unref = Timeout.prototype.ref = function() {};
Timeout.prototype.close = function() {this._clearFn.call(scope, this._id);
};// Does not start the time, just sets up the members needed.
exports.enroll = function(item, msecs) {clearTimeout(item._idleTimeoutId);item._idleTimeout = msecs;
};exports.unenroll = function(item) {clearTimeout(item._idleTimeoutId);item._idleTimeout = -1;
};exports._unrefActive = exports.active = function(item) {clearTimeout(item._idleTimeoutId);var msecs = item._idleTimeout;if (msecs >= 0) {item._idleTimeoutId = setTimeout(function onTimeout() {if (item._onTimeout)item._onTimeout();}, msecs);}
};// setimmediate attaches itself to the global object
require("setimmediate");
// On some exotic environments, it's not clear which object `setimmediate` was
// able to install onto.  Search each possibility in the same order as the
// `setimmediate` library.
exports.setImmediate = (typeof self !== "undefined" && self.setImmediate) ||(typeof global !== "undefined" && global.setImmediate) ||(this && this.setImmediate);
exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) ||(typeof global !== "undefined" && global.clearImmediate) ||(this && this.clearImmediate);复制代码

timers-browserify相关推荐

  1. browserify使用手册

    简介 这篇文档用以说明如何使用browserify来构建模块化应用 browserify是一个编译工具,通过它可以在浏览器环境下像nodejs一样使用遵循commonjs规范的模块化编程. 你可以使用 ...

  2. Browserify使用指南(转)

    让浏览器加载Nodejs模块 目前NPM上有二十多万个NodeJS模块,它们都是通过CMD的方式打包的,除了特定的可以使用CMD模块加载器加载的模块,大部分nodejs模块无法直接使用到浏览器环境中. ...

  3. browserify/browserify

    browserify require('modules') in the browser Use a node-style require() to organize your browser cod ...

  4. System.Timers.Timer的Enable、Start、Stop记录

    Timer的初始化,此时不执行theout3方法 System.Timers.Timer time = new System.Timers.Timer(); time.Interval = 1000; ...

  5. C# System.Timers.Timer中的坑,程序异常退出后timer依然运行问题

    C# System.Timers.Timer中的坑,程序异常退出后timer依然运行问题 参考文章: (1)C# System.Timers.Timer中的坑,程序异常退出后timer依然运行问题 ( ...

  6. System.Timers.Timer与System.Threading.Timer

    我最近一直在查看一些可能的计时器,而Threading.Timer和Timers.Timer对我来说是必要的(因为它们支持线程池). 我正在制作游戏,我计划使用不同类型的活动,间隔不同等. 哪个最好? ...

  7. Timers cannot be stopped from another thread

    Timers cannot be stopped from another thread 我发现的一种情况: 线程异常退出了,并不是线程本身有问题,是线程里面报错了.

  8. System.Timers.Timer 多线程问题[转]

    已解决问题] System.Timers.Timer 多线程 ,同时首次进 声明: System.Timers.Timer timer = new System.Timers.Timer(); tim ...

  9. System.Timers.Timer与System.Windows.Forms.Timer 区别

    根据msdn解释:System.Threading.Timer 是一个简单的轻量计时器,它使用回调方法并由线程池线程提供服务. 不建议将其用于 Windows 窗体,因为其回调不在用户界面线程上进行. ...

  10. STM32中的timers中断处理函数

    STM32中的timers中断处理函数 1.在固件库函数里面,用来读取中断状态寄存器的值判断中断类型的函数是: ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, ...

最新文章

  1. matplotlib库之patch
  2. linux注销、关机、重启
  3. c 文件夹打包解包_linux中文档的压缩与打包
  4. LOJ#2542 随机游走
  5. c语言程序设计B试题,c语言程序设计期末试题B(含答案)Word版
  6. 机器学习知识总结系列- 模型评估(1-2)
  7. 洛谷P4559 [JSOI2018]列队 【70分二分 + 主席树】
  8. python导入同一文件夹下的类_Python模块导入机制与规范
  9. python函数使用两个小括号
  10. install lsa package for R on ubuntu 10.04 lts lucid
  11. webpack异步加载业务模块
  12. Swift - 05 - 数值型字面量
  13. Q82:三角形网格[Triangle Mesh]图形的平滑着色[Smooth Shading]
  14. 网易整合邮箱和博客 可通过邮件更新博客日志
  15. 微软为“离线”做好准备:推出同步框架
  16. 剑圣一族x8鼠标驱动v1.21加强版
  17. linux vi命令怎么使用方法,linux vi命令的使用方法
  18. 机器学习十大算法原理总结
  19. R语言函数(1)-par()函数
  20. phyton 100题(更新中)

热门文章

  1. java-三元表达式详解
  2. Win10任务栏搜索框无法搜索,显示白色页面
  3. 第一章SQL数据库开发--TSQL概述
  4. 红旗Linux桌面4.1文本布置历程图解(四)
  5. Unity项目总结 模型制作 场景搭建
  6. 适用于互联网行业的员工手册
  7. Python脚本模拟按键Crtl+1,Crtl+2....实现浏览器标签自动切换
  8. element-plus table表格换行变色以及部分el自带样式的修改
  9. 如何才能提高便携式超声波流量计的精度
  10. ipoo3可以用鸿蒙,iQOO Neo3用实力来告诉我们,什么是强悍芯生生而为赢