[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

The const declaration in the outermost scope

ram

5/31/2016 1:17:00 PM

I use the following const declaration

"use strict";

/* g is declared here */

const f = () =>
{ "use strict";
f.zeit = document.getElementById( "Zeit" );
f.sekunden = 1;
setTimeout( g, 1000 ); }

. It works as intended. But actually I am surprised
that I already can use »f« in the declaration.

Let's try this:

"use strict";

console.log( 'Before, "f" in this = ' +( "f" in this ));

const f = () =>
{ console.log( 'In f, "f" in this = ' +( "f" in this ));
console.log( "In f, " + typeof f ); }

f();

console.log( 'Finally, "f" in this = ' +( "f" in this ));
console.log( "Finally, " + typeof f );

It prints:

Before, "f" in this = false
In f, "f" in this = false
In f, function
Finally, "f" in this = false
Finally, function
undefined

So, inside of »f«, it is already known that this is going
to be a function, even though the »assignment« to »f«
is not complete!

And after the execution of »f«, »f« is still a function,
but it is not stored in the global object »this«?

Where then are »global constants« stored?

Is there now a »global lexical environment« that is not
the same as the global object (cf. ECMAScript 13.1.1)?

3 Answers

The Horny Goat

3/10/2010 6:56:00 AM

0

On Tue, 09 Mar 2010 21:33:34 +1100, Phil McGregor
<aspqrz@pacific.net.au> wrote:

>>> In fact, one of the reasons why Hitler was able to do France in 1940
>>> was because of the *stockpiles* he'd captured in Poland and acquired
>>> in Czechoslovakia being enough, along with the small amounts
>>> produced
>>> by both those countries, to fuel the invasion ... or so I have read
>>> over the years in a couple of places.
>>
>>Sounds credible, but that's before Rumanian oil became available, of
>>course.
>
>No. Even after. Rumanian oil was, even with supplies from the USSR,
>never enough to meet demand.
>
>Evidently German stocks declined steadily from 1941 onwards to the
>point where, by late 1944, any "surplus" that the German records
>showed were, thanks to Speer's book-keeping (lying, basically), merely
>current production in transit. There were, essentially, no reserves at
>all. Even with Rumanian oil.
>
>Losing the Ploesti fields was, of course, the last straw.

It is difficult to imagine anything the Germans would consider victory
without Ploesti firmly in German hands.

Even Ploesti glowing in the dark with the rest of Europe in German
hands doesn't feel much like Germany to me.

Certainly even with both Ploesti and the Caucasian fields in German
hands they are hardpressed to outdo a fully mobilized United States.

Again for the umpteenth time, it is not enough for Germany to take the
Caucasian oilfields (or the Iraqi fields for that matter). The
important goal is transporting the oil to German factories which is a
much harder job.

I know you understand this Phil - it's Al and several others who
somehow have the idea that 1000 barrels in Baku is just as good as
1000 barrels in Berlin. T'ain't so and you know it!

aspqrz

3/10/2010 7:48:00 AM

0

On Tue, 09 Mar 2010 22:56:05 -0800, THG <lcraver@home.ca> wrote:

>On Tue, 09 Mar 2010 21:33:34 +1100, Phil McGregor
><aspqrz@pacific.net.au> wrote:
>
>>>> In fact, one of the reasons why Hitler was able to do France in 1940
>>>> was because of the *stockpiles* he'd captured in Poland and acquired
>>>> in Czechoslovakia being enough, along with the small amounts
>>>> produced
>>>> by both those countries, to fuel the invasion ... or so I have read
>>>> over the years in a couple of places.
>>>
>>>Sounds credible, but that's before Rumanian oil became available, of
>>>course.
>>
>>No. Even after. Rumanian oil was, even with supplies from the USSR,
>>never enough to meet demand.
>>
>>Evidently German stocks declined steadily from 1941 onwards to the
>>point where, by late 1944, any "surplus" that the German records
>>showed were, thanks to Speer's book-keeping (lying, basically), merely
>>current production in transit. There were, essentially, no reserves at
>>all. Even with Rumanian oil.
>>
>>Losing the Ploesti fields was, of course, the last straw.
>
>It is difficult to imagine anything the Germans would consider victory
>without Ploesti firmly in German hands.
>
>Even Ploesti glowing in the dark with the rest of Europe in German
>hands doesn't feel much like Germany to me.
>
>Certainly even with both Ploesti and the Caucasian fields in German
>hands they are hardpressed to outdo a fully mobilized United States.
>
>Again for the umpteenth time, it is not enough for Germany to take the
>Caucasian oilfields (or the Iraqi fields for that matter). The
>important goal is transporting the oil to German factories which is a
>much harder job.
>
>I know you understand this Phil - it's Al and several others who
>somehow have the idea that 1000 barrels in Baku is just as good as
>1000 barrels in Berlin. T'ain't so and you know it!

Indeed. Though I think Al, at least, sorta knows it.

Phil

ram

5/31/2016 2:32:00 PM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>const f = () =>
>{ "use strict";
> f.zeit = document.getElementById( "Zeit" );
> f.sekunden = 1;
> setTimeout( g, 1000 ); }
>. It works as intended. But actually I am surprised
>that I already can use »f« in the declaration.

Ok, I now believe that I understand this:

»f.zeit« is only evaluated later, when »f« is called.

>Is there now a »global lexical environment« that is not
>the same as the global object (cf. ECMAScript 13.1.1)?

Yes, as confirmed by the MDN article about »let«.