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. java 宽字节_宽字节注入
  2. windows监控——再见zmq
  3. ASP.NET WebApi技术从入门到实战演练
  4. 状态很差时,就不要再继续做了。因为是徒劳,再就是过段时间或第二天再看,会豁然开朗,原来存在的疑难问题都迎刃而解。平时没事的时候要不断地给自己充电,让自己了解多方面知识。...
  5. python数据可视化的特点_Python数据可视化 pyecharts实现各种统计图表过程详解
  6. 高通modem启动过程_苹果首次承认正自研基带芯片,高通要被抛弃了?
  7. pythonpptx 楷体_python-pptx 实践 4:添加形状、文本
  8. 利用 Domino V8 新特性开发 Mashup 应用(转载)
  9. 【Elasticsearch】elasticsearch 常用 API 介绍
  10. 我的世界服务器自定义怪物怎么用,我的世界 教你自定义怪物属性
  11. linux集群中mpi的并行计算环境简单配置,linux集群中MPI的并行计算环境简单配置(转)...
  12. matlab的unique函数
  13. java 内省 反射_java 反射与内省
  14. 怎么看R语言是不是在运行_生信技能树R语言视频课听后感 (10万+的播放量就看这个春节)...
  15. 2022最新手机号码正则
  16. java中.rtf文件变成文本文件
  17. 手动更新google服务框架
  18. html+css+js学习-01
  19. 学习python:练习2.投资理财计算器
  20. 腾讯员工税后收入 250 万,年终奖是100个月工资?在大厂工作究竟有多赚钱?

热门文章

  1. 教学案例五 循环结构
  2. zookeeper-3.5.5安装报错:找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain-新版本zookeeper易犯错误
  3. 【BIM模型生成点云数据】revit转obj格式,全网最详细最简单的步骤了!
  4. 手机内存不够大的请进!!!让你的sd卡变成手机内存
  5. linux dstat 监控软件,linux 性能检测工具之 dstat
  6. 小红书如何推广 方法总结
  7. 中国科学院大学21年计算机考研情况 分数线340分,不完全保护一志愿
  8. 汽车EDI:如何与Stellantis建立EDI连接?
  9. 隐蔽通信(Covert Communication)技术概述
  10. 十六进制转八进制(代码)