Self-Executing Anonymous Function
by joshrivers
HTML
<div id="text"></div>
<div id="error"></div>
JavaScript
window.onerror = function(errorMessage) {
$("#error").text(errorMessage);
};
function addText(text) {
$("#text").text($("#text").text() + text);
}
(function() {
var counter = 0;
window.addCount = function() {
counter++;
addText(counter + ", ");
};
})();
addCount();
addCount();
addCount();
addCount();
addCount();
addText(counter);