GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Monday, January 3, 2011

setTimeout In OOP Style

<h1>setTimeout In OOP</h1>
<h1 id="satu"></h1>

<script>
function Lol(id){
    this.i = 0;
    this.id = document.getElementById(id);
}
Lol.prototype.run = function(){
    this.i = this.i+1;
    this.id.innerHTML = this.i;
    var lol = this;               // use this
    setTimeout(function(){lol.run();},500);
};

var lola = new Lol('satu');
lola.run();

</script>
         

Share/Bookmark

No comments:

Post a Comment