Created
March 27, 2013 05:58
-
-
Save tkrajina/5252035 to your computer and use it in GitHub Desktop.
Minimalistic javascript assert with stacktrace.
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
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