Skip to content

Instantly share code, notes, and snippets.

@tkrajina
Created March 27, 2013 05:58
Show Gist options
  • Save tkrajina/5252035 to your computer and use it in GitHub Desktop.
Save tkrajina/5252035 to your computer and use it in GitHub Desktop.
Minimalistic javascript assert with stacktrace.
if(!window.assert) {
window.assert = function() {
if(!arguments.length || arguments < 2) {
alert('Invalid assert, use assert(expression, message1, message2, ...)')
return
}
var expression = arguments[0]
if(!expression) {
var message = ''
for(i = 1; i < arguments.length; i++) message += ' ' + arguments[i]
var error = new Error('Assert failed:' + message)
console.error(error)
console.error(error.stack)
throw error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment