You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

717 B

defer和nextTick有什么区别

研读FineUI代码时,会发现有的地方用了BI.defer,有的地方用了BI.nextTick,有什么区别呢?

BI.defer源自lodash,官方描述是Defers invoking the func until the current call stack has cleared.,翻译一下就是在当前调用栈执行完毕之后调用.

看起来很高大上实际上底层实现就是settimeout(fn,0)

BI.nextTick的实现相对复杂,采用的是"能力检测"策略,优先使用Promise.resolve(),不支持的话使用MutationObserver,不支持的话setImmediate,还是不支持的话 那就只能settimeout(fn,0)

由此可见,实际作用都是异步的延迟执行某段事务,使用BI.nextTick效率会更高一些