I have a function with parameters that do some operations on these parameters then send them to itself again with certain timeout Now i want to clear this timeout but at some point i want to recall that timeout that was cleared with its current parameters anyway to do this ?
var thread
$(document).ready(function(){
    f(0, 0)
    $('.pause').click(function(){
        clearTimeout(thread);
    });
    $('.resume').click(function(){
        thread; //want to rerun thread
    });
    f(x, y) {
        thread = setTimeout(function(){
            f(x + 1, y + 1);
        }, 1000)
    }
				
                        
You just need to call
f(0, 0)again in theresumeclick handler:If you want to continue on from where the
xandyvalues were paused, you need to store them first. Try this:Working example
Note that because the
publicXandpublicYvariables are now within the scope of all handlers you no longer need to include them as arguments of thef()function. I've left them in in this example in case you have some other logic which requires their use.