[Greasemonkey] Reference function
Johan Sundström
oyasumi at gmail.com
Tue Aug 8 14:40:46 EDT 2006
> unsafeWindow.timedCount = function () {
> ...
> var t = setTimeout ('timedCount ()', 1000);
> ...
> }
> unsafeWindow.timedCount();
>
> Can I do something to get it work without unsafeWindow? Cause I can't
> get it work with addEventListener due to the function looping...
Learn how to use function references instead of named functions.
In this case you should probably just keep the function to yourself in
the GM scope:
function timedCount()
{
...
setTimeout( timedCount, 1000 );
...
}
timedCount();
Registering it to invoke via addEventListener isn't any harder than
the setTimeout:
document.addEventListener( 'load', timedCount, false );
and in case you absolutely want to list the callback as an inline
function literal in that call (some do; personally I find it less
readable for anything but oneliners), the function has a reference to
itself known as arguments.callee which you could use instead of
timedCount in the setTimeout call.
--
/ Johan Sundström, http://ecmanaut.blogspot.com/
More information about the Greasemonkey
mailing list