Created
August 28, 2015 17:48
-
-
Save linus-amg/e3201b0dd7e8a78cbabd to your computer and use it in GitHub Desktop.
workaround optimization killers
This file contains 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
var errorObject = {value: null}; | |
function tryCatch(fn, ctx, args) { | |
try { | |
return fn.apply(ctx, args); | |
} | |
catch(e) { | |
errorObject.value = e; | |
return errorObject; | |
} | |
} | |
var result = tryCatch(mightThrow, void 0, [1,2,3]); | |
//Unambiguously tells whether the call threw | |
if(result === errorObject) { | |
var error = errorObject.value; | |
} | |
else { | |
//result is the returned value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment