param fn param time export const debounce = ( fn , time ) => { let timer = null ; return function ( ) { const self = debounce ; const args = arguments ; if ( timer ) { clearTimeout ( timer ) ; timer = null ; } timer = setTimeout ( ( ) => { fn . apply ( self , args ) ; } , time ) ; } ; } ; param fn param time export const throttle = ( fn , time ) => { let timer = null ; let lastTime = + new Date ( ) ; return function ( ) { const nowTime = + new Date ( ) ; const args = arguments ; const context = throttle ; if ( nowTime - lastTime > time ) { if ( timer ) { clearTimeout ( ) ; } ; fn . apply ( context , args ) ; lastTime = + new Date ( ) ; } else { if ( ! timer ) { timer = setTimeout ( ( ) => { fn . apply ( context , args ) ; lastTime = + new Date ( ) ; } , time - ( nowTime - lastTime ) ) ; } } } ; } ; param context export const canvasRatio = ( context ) => { const backingStore = context ? context . backingStorePixelRatio || context . webkitBackingStorePixelRatio || context . mozBackingStorePixelRatio || context . msBackingStorePixelRatio || context . oBackingStorePixelRatio || context . backingStorePixelRatio || 1 : 1 ; return ( window . devicePixelRatio || 1 ) / backingStore ; } ;