obj desc method method const fn = { curry : function < Return > ( fn ) : CurryFunction < Return > { let paramsLength = fn . length ; function closure ( params ) { let wrapper = function ( ... newParams ) { let allParams = [ ... params , ... newParams ] ; if ( allParams . length < paramsLength ) { return closure ( allParams ) ; } else { return fn . apply ( null , allParams ) ; } } ; return wrapper ; } return closure ( [ ] ) ; } , compose : function < Return > ( ... fn ) : ( ... params : any [ ] ) => Return { return ( ... params ) : Return => { let i = fn . length - 1 ; let result = fn [ i ] . apply ( null , params ) ; while ( -- i >= 0 ) { result = fn [ i ] ( result ) ; } return result ; } ; } , debounce : function < Return > ( fn , wait , immediate ) : Executor < Return > { const now = Date . now . bind ( Date ) ; let lastTime = 0 ; let timer = null ; let params = null ; let _this = null ; function later ( ) { const nowTime = now ( ) ; if ( nowTime - lastTime < wait ) { const remainTime = wait - ( nowTime - lastTime ) ; timer = setTimeout ( later , remainTime ) ; } else { debouncer . result = fn . apply ( _this , params ) ; timer = null ; _this = null ; params = null ; } } function execute ( ) { lastTime = now ( ) ; _this = this ; params = arguments ; try { if ( immediate && timer === null ) { debouncer . result = fn . apply ( _this , params ) ; } return debouncer . result ; } finally { if ( timer === null ) { timer = setTimeout ( later , wait ) ; } } } const debouncer = { execute , result : null , } ; return debouncer ; } , throttle : function < Return > ( fn , wait , { isExecuteAtStart = true , isExecuteAtEnd = true , } = { isExecuteAtStart : true , isExecuteAtEnd : true , } ) : Executor < Return > { let timer = null ; let _this = null ; let params = null ; function execute ( ) { _this = this ; params = arguments ; if ( isExecuteAtStart && timer === null ) { executor . result = fn . apply ( _this , params ) ; _this = null ; params = null ; } if ( isExecuteAtEnd ) { if ( timer === null ) { timer = setTimeout ( function ( ) { executor . result = fn . apply ( _this , params ) ; _this = null ; params = null ; timer = null ; } , wait ) ; } } return executor . result ; } const executor = { execute , result : null } ; return executor ; } } ; export default fn ; export const curry = fn . curry ; export const compose = fn . compose ; export const debounce = fn . debounce ; export const throttle = fn . throttle ;