Last active
October 27, 2015 23:29
-
-
Save taka011239/bb91d7d24aff65501da9 to your computer and use it in GitHub Desktop.
callbackをasyncにする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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