Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27940
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Expression for the global object |
| Date | 2015-05-31 14:56 +0100 |
| Organization | A noiseless patient Spider |
| 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> |
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
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