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


Groups > comp.lang.javascript > #27560

Re: ! function

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: ! function
Date Thu, 07 May 2015 23:27:37 +0200
Organization solani.org
Lines 41
Message-ID <miglc1$4s6$1@solani.org> (permalink)
References <ddSdncub_tOuptbInZ2dnUVZ8gidnZ2d@westnet.com.au> <mig09m$not$1@speranza.aioe.org> <XnsA493D6D7F9E67eejj99@194.109.133.246> <migej4$beq$1@solani.org> <XnsA493E3574B657eejj99@194.109.133.246>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1431034049 4998 eJwFwYEBgDAIA7CXGKVMzhGw/59gQuTJuZHMoCis+XS1YVx6hFpP+4YIBqDP39tdtqcQmP0BIDwRJg== (7 May 2015 21:27:29 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Thu, 7 May 2015 21:27:29 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
X-User-ID eJwFwYEBACAEBMCVKnyME97+I3Rngo26CoPa2Ei4JCICJ9nNa0wdP5tcuwrOaAyfleZ6/j4ibhHY
In-Reply-To <XnsA493E3574B657eejj99@194.109.133.246>
Cancel-Lock sha1:xJg6Vmxl4ZIeuXNsAbXeb9mUaeE=
X-NNTP-Posting-Host eJwNysERACEIBMGUTmSgCMdaJP8Qzn43O1YoPQhnGPX5UNUUXCusYnRztTWJeJkTWsdc9OwfIRcRPw==
Xref csiph.com comp.lang.javascript:27560

Show key headers only | View raw


Evertjan. wrote:

> "Christoph M. Becker" <cmbecker69@arcor.de> wrote on 07 mei 2015 in 
> comp.lang.javascript:
> 
>>  to enforce an expression context.
> 
> No "expression context" [I hope you mean 'scope'] is forced,
> the return value is just accepted as required.

No, I don't mean "scope".  I was referring to *parsing*; however, the
term "expression context" might be misleading.

> But why does this work:
> 
> -function(a){alert(a);return 2}('hi')
>
> and this does not:
> 
> function(a){alert(a);return -2}('hi')
> 
> ??

This is a syntax issue.  See annex A of ECMA-262 5.1 Edition[1].  The
first line is parsed as (simplified)

  SourceElement -> Statement -> Expression -> UnaryExpression -> -
UnaryExpression -> - FunctionExpression Arguments -> ...

while the second line is parsed as (again simplified)

  SourceElement -> FunctionDeclaration -> ...

and the remaining ('hi') is a syntax error, as no ASI applies here.

[1] <http://www.ecma-international.org/ecma-262/5.1/#sec-A>

-- 
Christoph M. Becker

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


Thread

! function Andrew Poulos <ap_prog@hotmail.com> - 2015-05-07 20:15 +1000
  Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 13:04 +0200
  Re: ! function "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-07 05:02 -0700
  Re: ! function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-07 12:27 -0300
    Re: ! function JJ <jj4public@vfemail.net> - 2015-05-08 00:09 +0700
    Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 21:07 +0200
      Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-07 21:31 +0200
        Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 22:20 +0200
          Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-07 23:27 +0200
            Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-08 00:26 +0200
              Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-08 11:00 +0200
                Re: ! function James Lewis <lewisje@gmail.com> - 2015-06-05 09:10 -0700
          Re: ! function Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-18 13:31 -0700
            Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-19 01:39 +0200
              Re: ! function Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-19 05:48 -0700
        Re: ! function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-07 17:47 -0300
          Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 23:22 +0200
            Re: ! function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-07 19:08 -0300
              Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-08 12:08 +0200

csiph-web