Skip to content

Instantly share code, notes, and snippets.

@s3rgeym
Last active March 9, 2018 13:01
Show Gist options
  • Save s3rgeym/2d014a8f6cc12d02d0517b025a5fab98 to your computer and use it in GitHub Desktop.
Save s3rgeym/2d014a8f6cc12d02d0517b025a5fab98 to your computer and use it in GitHub Desktop.
JavaScript assert
// Ошибку, генерируюмую 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