[Laszlo-dev] Someone should see if `var global = this` at top level works in swf9

Donald Anderson dda at ddanderson.com
Tue Jul 29 07:06:24 PDT 2008


Nope - didn't work for me like that, got this error:

    The this keyword can not be used in static methods. It can only be  
used in instance methods, function closures, and global code, in  
line:   public var globalthis = this;}

The line compiles into its own file globalthis.as:

   package {
   public var globalthis = this;}

You can use 'this' as long as it isn't in a var initializer however.
You can use this to indirectly set the global variable if you want.
For example, this works:

   var globalthis;
   function setThis(thisvar) {
     globalthis = thisvar;
   }
   setThis(this);

   function stuff(foo) {
   }
   stuff(globalthis); // I can use the globalthis now.


On Jul 29, 2008, at 9:20 AM, P T Withington wrote:

> As a way to create an alias to the global object, like we have in  
> every other runtime.


--

Don Anderson
Java/C/C++, Berkeley DB, systems consultant

voice: 617-547-7881
email: dda at ddanderson.com
www: http://www.ddanderson.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20080729/5e0b6665/attachment-0001.html


More information about the Laszlo-dev mailing list