[Greasemonkey] Javascript lexical scoping question

Bill Donnelly donnelly at snowcrest.net
Thu Apr 14 21:51:48 EDT 2005


By default, I think "this", in this context,
defaults to the current window OBJECT,
until a different context is selected/created.

Which, for example, is the window object context
in which the Gm script is loaded. (global, or otherwise)

If I'm not mistaken, and I never am ;o),
iframes have a separate window object than
the primary "document". And I think each frame
might also have it's own window object,
but I'm not so sure about that.

That's why I had to change my color corrector
script to use "this.addEventListener" to set
the onload function to execute in the right context.
(window.addEventListener was always making the
function execute in the global window object context)

 > function test() { var internal = 5; this.visible = 6; }
 > props(test);

More information about the Greasemonkey mailing list