Skip to content

Instantly share code, notes, and snippets.

@jgermade
Created December 8, 2016 22:23
Show Gist options
  • Save jgermade/c1eb7f9ee116b81f46f6929a653beda9 to your computer and use it in GitHub Desktop.
Save jgermade/c1eb7f9ee116b81f46f6929a653beda9 to your computer and use it in GitHub Desktop.
function delayed (fn, args) {
var _this = this, _args = args || arguments;
setTimeout(function () {
fn.apply(_this, _args);
}, 0);
}
function once (fn, nextValue) {
var result, hasNextValue = arguments.length > 1;
return function () {
if( fn ) {
result = fn.apply(this, arguments);
fn = null;
return result;
}
return hasNextValue ? nextValue : result;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment