import { ThrottleOptions } from './throttle-options.interface' ; param func param wait param options returns export function throttle ( func , wait , options ? ) { options = options || { } ; let context ; let args ; let result ; let timeout = null ; let previous = 0 ; const later = ( ) => { previous = options . leading === false ? 0 : + new Date ( ) ; timeout = null ; result = func . apply ( context , args ) ; } ; return function ( ) { const now = + new Date ( ) ; if ( ! previous && options . leading === false ) { previous = now ; } const remaining = wait - ( now - previous ) ; context = this ; args = arguments ; if ( remaining <= 0 ) { clearTimeout ( timeout ) ; timeout = null ; previous = now ; result = func . apply ( context , args ) ; } else if ( ! timeout && options . trailing !== false ) { timeout = setTimeout ( later , remaining ) ; } return result ; } ; }