setTImeout extra parameters
re: http://twitter.com/kuvos/status/15151040085102592
by desandro
HTML
<div id="output"></div>
CSS
body {
font-family: 'Helvetica Neue', Arial, sans-serif;
font-weight: 300;
}
JavaScript
var Annoyer = function( element ) {
this.element = element;
this.count = 0;
this.annoy();
}
Annoyer.prototype.getNth = function() {
if ( this.count > 10 && this.count < 20 ) {
return 'th'
} else {
var oneDigit = this.count % 10;
switch ( oneDigit ) {
case 1 : return 'st'; break;
case 2 : return 'nd'; break;
case 3 : return 'rd'; break;
default: return 'th';
}
}
};
Annoyer.prototype.annoy = function() {
this.count++;
var sentence = document.createElement('sentence');
sentence.textContent += ' Really, for the ' + this.count + this.getNth() + ' time?';
sentence.style.fontSize = ( this.count + 8 ) + 'px';
this.element.appendChild( sentence );
setTimeout( function( instance ) {
instance.annoy();
}, 200, this );
};
var myAnnoyer = new Annoyer( document.getElementById('output') );