Call setTimeout or setInterval function in an Objects Method

0

The ticker above is a result of code listed below. This simple demo shows how to call setTimeout function from object's method.


<script type="text/javascript">
    function obj(){
        var duration = 1000;
        var tmFunc = function(){ exec(); }; 
        setTimeout(tmFunc, duration);
        function exec(){
            var value = parseInt(document.getElementById('element').innerHTML);
            value++;
                        
            document.getElementById('element').innerHTML = value;
            setTimeout(tmFunc, duration);            
        }                
    }
    obj = new obj();
</script>
    

View Full Tutorial: Call setTimeout or setInterval function in an Objects Method

The ajaxBlender team specializes in web development to build advanced, interactive JavaScript/AJAX web applications driven by jQuery, MooTools, Ext.JS, and script.aculo.us on various server-side platforms including PHP and ASP.NET.