还在用Date.now()吗?试试performance.now()

728 阅读1分钟

redux-logger源码里看到这一块,所以想记录下

// Use performance API if it's available in order to get better precision
export const timer =
(typeof performance !== 'undefined' && performance !== null) && typeof performance.now === 'function' ?
  performance :
  Date;
  
// use statement
logEntry.started = timer.now();

优先使用performance.now()来代替Date.now()