Skip to content

Instantly share code, notes, and snippets.

Timebinder

I need a utility function. Let's call the function timebinder. This timebinder function expects two arguments: the first is a callback function, and the second is a number that represents some amount of milliseconds. The return value of the timebinder function is another function.

The function returned by timebinder expects a single argument: a context. When I call the returned function and pass a context, there is no return value. Then, the original callback function that I passed to timebinder should be called at the number of milliseconds I specified in the future.

Here are some example usages (assume we are executing in the browser window context):

var callback = function() {