Skip to content

Instantly share code, notes, and snippets.

@mrbobbybryant
Created December 14, 2015 14:38
Show Gist options
  • Select an option

  • Save mrbobbybryant/875101aea11f67718d71 to your computer and use it in GitHub Desktop.

Select an option

Save mrbobbybryant/875101aea11f67718d71 to your computer and use it in GitHub Desktop.
Ensures a function is only called once.
//Once
function once(fn) {
var done = false;
return function() {
return done ? void 0 : ((done = true), fn.apply(this, arguments));
};
}
var askedOnBlindDate = once(function () {
return 'sure, why not?';
});
console.log(askedOnBlindDate());
console.log(askedOnBlindDate());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment