A bit confused by B.3.2 - Web Legacy Compatibility for Block-Level Function Declarations

Mameri, Fred (HBO) Fred.Mameri at hbo.com
Thu Jun 5 08:18:12 PDT 2014


We don't need an identifier for global. Much like with the :: operator in C++, a member expression starting with a . would always refer to the global object.
So if you want to refer to member "foo" in the global object, ".foo" would be unambiguous.
I feel like it's a simple, yet elegant solution.

--F

From: John Barton <johnjbarton at google.com<mailto:johnjbarton at google.com>>
Date: Thursday, June 5, 2014 at 10:55 AM
To: Andreas Rossberg <rossberg at google.com<mailto:rossberg at google.com>>
Cc: es-discuss <es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>>
Subject: Re: A bit confused by B.3.2 - Web Legacy Compatibility for Block-Level Function Declarations

Assigning to 'this' because it happens that 'this' is global is no better and perhaps worse than using undeclared variables for globals. Assignments to global have, well, non-local consequences: they should be explicit not context dependent.

Even if you don't agree, node has made "global" the de facto standard; lots of code is now written with the (function(global) {...}(typeof global !== 'undefined' ? global : this)); goop.  Modules avoid the smaller part of that boilerplate but we still don't solve it all without a way to say "global".


On Thu, Jun 5, 2014 at 7:34 AM, Andreas Rossberg <rossberg at google.com<mailto:rossberg at google.com>> wrote:
On 5 June 2014 16:08, John Barton <johnjbarton at google.com<mailto:johnjbarton at google.com>> wrote:
> On Thu, Jun 5, 2014 at 2:06 AM, Andreas Rossberg <rossberg at google.com<mailto:rossberg at google.com>>
> wrote:
>>
>> On 4 June 2014 23:46, John Lenz <concavelenz at gmail.com<mailto:concavelenz at gmail.com>> wrote:
>> > I don't personally want to write sloppy mode code, but there are places
>> > you
>> > need it (using eval to introduce new symbols into global scope).
>>
>> You don't necessarily need sloppy mode for that. In strict mode, you
>> can still express it as assignment to the global object.
>
> This excellent solution would be much more widely adopted if the global
> object had a standard identifier, like say "global".

Hm, I'm not sure why that would be a problem. What's wrong with using
'this' inside those evals?

/Andreas


---------------------------------------------------------------------
This e-mail is intended only for the use of the addressees.  Any copying, forwarding, printing or other use of this e-mail by persons other than the addressees is not authorized.  This e-mail may contain information that is privileged, confidential and exempt from disclosure. If you are not the intended recipient, please notify us immediately by return e-mail (including the original message in your reply) and then delete and discard all copies of the e-mail. 

Thank you.

---------------------------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140605/0dfd6a13/attachment-0001.html>


More information about the es-discuss mailing list