Created
August 30, 2011 01:36
-
-
Save joshkehn/1179927 to your computer and use it in GitHub Desktop.
One-shot setters
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
// 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