<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>
<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>
No comments:
Post a Comment