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


Groups > comp.lang.javascript > #27940

Re: Expression for the global object

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: Expression for the global object
Date Sun, 31 May 2015 14:56:30 +0100
Organization A noiseless patient Spider
Lines 45
Message-ID <87382cj1f5.fsf@bsb.me.uk> (permalink)
References <JavaScript-20150528222318@ram.dialup.fu-berlin.de> <Function-20150531094321@ram.dialup.fu-berlin.de> <87twuthx5h.fsf@bsb.me.uk> <5452925.Zt9fTqAOub@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Injection-Info mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="10174"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uTRHunvSGe7P69DLSPBPskbKI73alnmA="
Cancel-Lock sha1:ibSgsumF8mC040VflneUyqtkIzM= sha1:lEVYREEVLd7dNrXuoQjmBaM/xbw=
X-BSB-Auth 1.9ccc04145f0849d07834.20150531145630BST.87382cj1f5.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:27940

Show key headers only | View raw


Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> Ben Bacarisse wrote:
>
>> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>>> What is the smallest scope- and host-independent expression
>>>> whose value is the global object?
>>> Function("return this")()
>> 
>> How does that help?  The identifier Function is looked-up like any
>> other.
>
> My test in Chromium 43¹ shows that this approach helps insofar that, 
> different from the code of functions defined with a /FunctionDeclaration/ or 
> /FunctionExpression/, this function code is only “strict function code […] 
> if the function code begins with a Directive Prologue that contains a Use 
> Strict Directive” [1][2]:
>
>   Function('"use strict"; …')();
>
> So if “Function” refers to the Function constructor, that expression – 
> regardless whether the constructor is called as a function, without “new” – 
> returns a reference to the global object, regardless whether the calling 
> execution context is in strict mode.  (I stand corrected.)

Oh, did you say otherwise?  I suggested using Function when you pointed
out the flaw in using thunk that returns this (my first suggestion), but
you didn't reply to that post (as far as I can recall).

You did say it could not be done, but that is probably true.  Your
argument was based on the treatment of identifiers, so another argument
is needed to show that there is no way to do it without any.  I can
think of other ways to do it[1], but I can't think of one that does not
use some identifier or other.

[1] For example, an indirect call to eval also works:

  (function () { return eval; })()("this")

but, again, not for Stefan's purpose.

<snip>
-- 
Ben.

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


Thread

Re: Expression for the global object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 11:14 +0100
  Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-31 15:08 +0200
    Re: Expression for the global object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 14:56 +0100
      Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-31 16:12 +0200
        Re: Expression for the global object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 15:57 +0100
          Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-31 17:33 +0200
            Re: Expression for the global object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 16:41 +0100
      Re: Expression for the global object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-31 16:21 +0200

csiph-web