I’m writing an assert function. How do I cache #assert if it doesn’t exist yet?
function assert( outcome, description ) {
if (!$('#assert').length) {
$('body').append('<ul id="assert"></ul>');
}
$('#assert').append('<li class="' + (outcome ? 'hide' : 'alert-danger') + '">' + description + '</li>');
}
I’d do it like this…
Or if the
assertelement is meant to be used by subsequent invocations, I’d probably use a closure to maintain a reference between calls…You could expand on this by returning several functions…
and use it like this…