0.1.1 • Published 7 years ago

nexttick-polyfill v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

nextTick polyfill

  • Node.js use process.nextTick()
  • Browser :
    • MutationObserver ? MutaionObserver :
    • Promise ? Promise.resolve().then :
    • setImmediate ? setImmediate :
    • setTimeout

Usage

npm i nexttick-polyfill;

nexttick-polyfill(fn);

Understanding process.nextTick()

nextTick的兼容包

  • Node端: 直接使用process.nextTick()
  • 浏览器端:
    • 支持MutaionObser事件则使用,否则
    • 支持Promise则使用Promise.resolve().then,否则
    • 支持setImmediate则使用,否则
    • 使用setTimeout

使用

npm i nexttick-polyfill;

nexttick-polyfill(fn);

setTimeout和setImmediate以及process.nextTick的区别