Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: ! function Date: Thu, 07 May 2015 23:27:37 +0200 Organization: solani.org Lines: 41 Message-ID: References: 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: Cancel-Lock: sha1:xJg6Vmxl4ZIeuXNsAbXeb9mUaeE= X-NNTP-Posting-Host: eJwNysERACEIBMGUTmSgCMdaJP8Qzn43O1YoPQhnGPX5UNUUXCusYnRztTWJeJkTWsdc9OwfIRcRPw== Xref: csiph.com comp.lang.javascript:27560 Evertjan. wrote: > "Christoph M. Becker" 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] -- Christoph M. Becker