[Laszlo-dev] Someone should see if `var global = this` at top level works in swf9
Donald Anderson
dda at ddanderson.com
Tue Jul 29 08:19:15 PDT 2008
Yes, that compiles and appears to run.
On Jul 29, 2008, at 10:26 AM, P T Withington wrote:
> Ok, that is interesting. So, perhaps I could say:
>
> var global = (function () { return this; })();
> var foo = {bar: 'bar'};
> global.foo === foo
> ?
>
> I.e., can I actually capture the global object and peer into it?
>
> On 2008-07-29, at 10:06EDT, Donald Anderson wrote:
>
>> 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
>>
>>
>>
>
--
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/39b691b3/attachment-0001.html
More information about the Laszlo-dev
mailing list