Skip to content

Instantly share code, notes, and snippets.

@taka011239
Last active October 27, 2015 23:29
Show Gist options
  • Save taka011239/bb91d7d24aff65501da9 to your computer and use it in GitHub Desktop.
Save taka011239/bb91d7d24aff65501da9 to your computer and use it in GitHub Desktop.
callbackをasyncにする
function asyncify(fn) {
var origFn = fn;
var id = setTimeout(function () {
id = null;
if (fn) fn();
});
fn = null;
return function () {
if (id) {
fn = origFn.bind.apply(
origFn,
[this].concat([].slice.call(arguments)));
} else {
origFn.apply(this, arguments);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment