Skip to content

Instantly share code, notes, and snippets.

@joshkehn
Created August 30, 2011 01:36
Show Gist options
  • Save joshkehn/1179927 to your computer and use it in GitHub Desktop.
Save joshkehn/1179927 to your computer and use it in GitHub Desktop.
One-shot setters
// One-shot set function
function error (fn)
{
// Create locally bound copy of `fn`
var handle = fn.bind(this);
// Overwrite function
error = handle;
}
// Set the error handling function
error(function () {
console.log('An error occured.');
});
try {
undef('This throws.');
} catch (e) {
error();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment