[Greasemonkey] setTimeout() problems
Jonathan Buchanan
jonathan.buchanan at gmail.com
Wed May 24 15:04:52 EDT 2006
setTimeout needs a function to execute - you're immediately calling
the function you just defined, so as you're not returning anything in
that function, you're really passing undefined to setTimeout.
Try returning a function which forms a closure over the argument.
function(arg) { return function() { alert(arg); }; }(foo);
Jonathan.
On 5/24/06, Premshree Pillai <premshree.pillai at gmail.com> wrote:
> Hi group,
>
> I'm using a setTimeout within a userscript. The function that I need
> to pass as argument accepts an argument. Sample code:
>
> var foo = "bleh";
> window.setTimeout(function(arg) { alert(arg); }(foo), 300);
>
> I get an error--"useless setTimeout call (missing quotes around
> argument?)"--on execution.
>
> Any thoughts?
>
> Premshree
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
More information about the Greasemonkey
mailing list