www.webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Resources API Reference Mojo.Function.debounce(onCall, onTimeout, delay, optionalWindow)

Mojo.Function.debounce(onCall, onTimeout, delay, optionalWindow)

Function to "debounce" multiple calls to a function, causing it to be called only once.  Can also be used to call a seconday function if the primary function has not been called after some specified delay.  Returns wrapped onCall function that can be called like the original function.  Upon calling the wrapped function, the onCall function is called immediately and the onTimeout function called if the wrapper is not called again within the specified delay.  Arguments passed to the onTimeout function are the same as those passed to the last call of the wrapped function.

Example usage:

// this.clearSearchString() will be called 1 second after the most recent call to this.delayedClear().

this.delayedClear = Mojo.Function.debounce(undefined, this.clearSearchString.bind(this), 1, this.controller.window);
Parameter Type Description
onCall Function Function called when the wrapper is invoked.  May be undefined.
onTimeout Function Function called if the wrapper has not been invoked after the specified delay elapses.
delay Integer Time in seconds before onTimeout is called.
optionalWindow String The window the delay time runs in.  Defaults to window.
 

0 Comments

    Add Comment


      • >:o
      • :-[
      • :'(
      • :-(
      • :-D
      • :-*
      • :-)
      • :P
      • :\
      • 8-)
      • ;-)