Thanks!
Gordan :-)
"Douglas Crockford" <nospam@laserlink.net> wrote in message
news:bkc866$bvu$1@sun-news.laserlink.net...[color=blue][color=green]
> > i want to have a "close" button that user can click but that will also
> > "click itself after 10 sec"[/color]
>[color=green]
> > function auto_close(x)
> > {
> > if (x > 0){ document.form.button.value="CLOSE (auto close in "+ x +"[/color][/color]
sec)";[color=blue][color=green]
> > x--;
> > setTimeout("auto_close(x);", 1000);
> > } else self.close();
> > }
> >
> > and i put onload = auto_close(10);
> >
> > the problem is that the first time the recursion is called (
> > setTimeout("auto_close(x);",1000);) IE says x is undifined[/color]
>
> x is a local var of auto_close. When setTimeout finally evaluates the[/color]
string, it[color=blue]
> is not inside of auto_close, so the value of x is not available.
>
> You can get around this by passing a function instead.
>
> setTimeout(function () {
> auto_close(x);
> }, 1000);
>
> Static binding gives that function access to x.
>
>
http://www.crockford.com/javascript/inheritance.html
>[/color]