Q:

parameter of a function used in turn as parameter of setTimeout function in javascript

function f1()
{
  c = setTimeout(f2,200);
}
function f2()
{
 //code
}

The above code is just fine. But what I want to ask that: can I use some argument in function f2() which is passed from the calling environment? That is:
 function f1(v1)
    {
      c = setTimeout(f2(v1),200);
    }
    function f2(v2)
    {
     //code
    }

Is it valid? Because I tried something like this,but the problem is that I am not able to clearTimeout by using variable c. I am not sure what to do. 

A:

Use Closure - 
function f1(v1)
{
    c = setTimeout(f2(v1), 200);
}

function f2(v2)
{
     return function () {
         // use v2 here, and put the rest of your
         // callback code here.
     }
}

This way you will be able to pass as many arguments as you want.
Since you are declaring c as a global variable (which is bad), you can easily clear the timeout using - 
clearTimeout(c);

If you are still not being able to clear the timeout, it only means that the duration has elapsed and your callback fired, or there is some error somewhere else. In that case, post your code that you are using to clear your timeout.

