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


Groups > comp.lang.javascript > #27945

Re: Expression for the global object

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: Expression for the global object
Date 2015-05-31 15:57 +0100
Organization A noiseless patient Spider
Message-ID <87wpzohk1k.fsf@bsb.me.uk> (permalink)
References (1 earlier) <Function-20150531094321@ram.dialup.fu-berlin.de> <87twuthx5h.fsf@bsb.me.uk> <5452925.Zt9fTqAOub@PointedEars.de> <87382cj1f5.fsf@bsb.me.uk> <7546503.qSl4iIXIz1@PointedEars.de>

Show all headers | View raw


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

> Ben Bacarisse wrote:
>
>> (function () { return eval; })()("this")
>
> In all respects equivalent to
>
>   eval("this")
>
> which is equivalent to
>
>   this

Given:

  'use strict';
  console.log((function () { return eval; })()("this") === global);
  console.log(eval("this") === global);
  console.log(this === global);

nodejs prints:

  NaN
  undefined
  undefined

(global is nodejs specific, of course, but there are other simple ways
to test the value).

> which is why it does not return a reference to the global object, but the 
> “undefined” value, in strict function code that is not called as the method 
> of an object.
>
> <http://ecma-international.org/ecma-262/5.1/#sec-10.4.2>

Sure, but what does 15.1.2.1.1 (Direct Call to Eval) have to say about
it?  You can interpret the words there much more readily than I can, and
it would seem that at least one implementation has decided that the
evaluation of the thunk above is not a "direct call to eval".

-- 
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