Created
September 15, 2009 21:15
-
-
Save kodi/187651 to your computer and use it in GitHub Desktop.
usage of timeout in Object Oriented Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
var Counter=function(){ | |
//public properties | |
this.counter=1; | |
this.resultDiv=document.getElementById('result'); | |
//methods | |
this.count=function(){ | |
//ispisi text u div | |
this.resultDiv.innerHTML='Prolaz broj '+this.counter; | |
//uradi to 10 puta | |
if(this.counter < 10) { | |
var self=this; | |
var timeoutFunc=function(){ self.count(); } //referenca metode na samu sebe | |
this.timer=setTimeout (timeoutFunc, 350 ); // timeout u ms | |
} | |
//povecaj counter | |
this.counter+=1; | |
} | |
} | |
//sacekaj da se sve prvo ucita | |
window.onload=function(){ | |
var c=new Counter(); | |
c.count(); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="result"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment