Last active
March 9, 2018 13:01
-
-
Save s3rgeym/2d014a8f6cc12d02d0517b025a5fab98 to your computer and use it in GitHub Desktop.
JavaScript assert
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
// Ошибку, генерируюмую console.assert, перехватить не удастся. | |
class AssertionError extends Error { | |
constructor(message) { | |
super(message) | |
Error.captureStackTrace(this, this.constructor) | |
} | |
} | |
function assert(test, message = 'Assertion failed') { | |
if (!test) { | |
throw new AssertionError(message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment