Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27924

Re: Expression for the global object

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Expression for the global object
Date 2015-05-29 17:24 +0200
Organization PointedEars Software (PES)
Message-ID <12824458.XGgQv3ng7H@PointedEars.de> (permalink)
References <JavaScript-20150528222318@ram.dialup.fu-berlin.de> <645d86ba-2299-4371-bb64-90dae6df316a@googlegroups.com> <1442639.SsZ0RATE5U@PointedEars.de> <79b520ed-6efe-4064-a9cf-ea66c60f00df@googlegroups.com>

Show all headers | View raw


Michael Haufe (TNO) wrote:

> […] Thomas 'PointedEars' Lahnwrote:
>> Michael Haufe (TNO) wrote: 
>> > On Thursday, May 28, 2015 at 3:27:31 PM UTC-5, Stefan Ram wrote:
>> > [...]
>> >>   What is the smallest scope- and host-independent expression
>> >>   whose value is the global object?
>> > 
>> > g
>> > 
>> > where g defined in a scope without "use strict" as the expression:
>> > 
>> > (function(){return this}).call(null)
>> 
>> This is not going to work.  Strict mode is hereditary.
> 
> You are correct that it is hereditary, but I am correct (if not
> over-general) when I said: 'a scope without "use strict"'. I left out the
> work "lexical' on purpose.

There is only lexical scoping in ECMAScript implementations, so what is 
omitting “lexical” supposed to change?

,-<http://ecma-international.org/ecma-262/5.1/#sec-8.6.2>
| 
| Internal Property    Value Type Domain      Description
| […]
| [[Scope]]            Lexical Environment    A lexical environment that
|                                             defines the environment in
|                                             which a Function object is 
|                                             executed. Of the standard 
|                                             built-in ECMAScript objects, 
|                                             only Function objects 
|                                             implement [[Scope]].

Consider this code:

  "use strict";

  (function () {
    var g = (function(){return this}).call(null);

    /* "null" */
    console.log(g);
  }());

The (lexical) scope in which “g” is defined as required per your suggestion 
is that of the function.  This scope is obviously “without "use strict"”.  
But it still does not work (“g” holds “null”, not a reference to the global 
object).  Conclusion: Your statement is wrong, and you are _not_ correct.

It is possible that you have been mislead by the Chrome Dev Console.  If you 
write

  "use strict"; // …

the strict declaration has no effect.  This has to do with how statements 
are evaluated by the Console.  You need to write

  (function () {
    "use strict";

    // …
  }());

to test strict mode there.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Expression for the global object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-28 13:49 -0700
  Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-28 22:59 +0200
    Re: Expression for the global object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-29 07:24 -0700
      Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-29 17:24 +0200
        Re: Expression for the global object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-30 06:07 -0700
          Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-30 15:20 +0200
            Re: Expression for the global object Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-30 11:23 -0300
              Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-30 19:05 +0200
  Re: Expression for the global object Steven D'Aprano <steve@pearwood.info> - 2015-05-29 15:30 +1000
    Re: Expression for the global object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-29 12:25 +0100
      Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-29 13:33 +0200
        Re: Expression for the global object Steven D'Aprano <steve@pearwood.info> - 2015-05-29 21:50 +1000
          Re: Expression for the global object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-29 14:57 +0100
            Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-31 16:18 +0200
  Re: Expression for the global object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-29 07:31 -0700
    Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-30 15:25 +0200
  Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-30 18:56 +0200

csiph-web