Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Created April 20, 2010 22:10
Show Gist options
  • Save coolaj86/373144 to your computer and use it in GitHub Desktop.
Save coolaj86/373144 to your computer and use it in GitHub Desktop.
// Douglas Crockford's once
// Part 5: The End of All Things, Slide 39
// Once or throw exception
function once(func) {
return function () {
var f = func;
func = null;
return f.apply(this, arguments);
}
};
do_it(my_inputs, once(storer(my_object, 'blah')));
// AJ ONeal
// Once or alert
function once(func) {
return function () {
var f = func;
func = null;
return f && f.apply(this, arguments) || alert('Did a bad thing...');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment