Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!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: Tue, 19 May 2015 01:39:57 +0200 Organization: solani.org Lines: 38 Message-ID: <555A784D.5050700@arcor.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: solani.org 1431992394 28199 eJwFwQEBwCAMAzBLg9O1yBnj9S+BBF+ObK5ELhju4+HiPKXaJW/R67bjhxmTSd0bkJIjWng4nxFO (18 May 2015 23:39:54 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 18 May 2015 23:39:54 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Scott Sauyet X-User-ID: eJwFwYEBgDAIA7CXBGkL5wwm/59ggpfGURAMLLYdx5zWvYZAayoyVKxPwn38KMX0+Tanb/0LqxC9 In-Reply-To: Cancel-Lock: sha1:MklHpJLxKhEKeVtmKrBO6ETAXlQ= X-NNTP-Posting-Host: eJwFwYEBwCAIA7CXhtCi50i3/n/CEiSD6iJYMLwk91iZonJxT9c6vNAlfXY8MYwG03i/wg8jFxDc Xref: csiph.com comp.lang.javascript:27748 Scott Sauyet wrote: > Evertjan. wrote: > >> Christoph M. Becker wrote >> >>> That's wrong. According to ES 5.1 the line can't be parsed as >>> FunctionDeclaration, because the Identifier is missing. Actually, the >>> code doesn't match any production, and as such is syntactically invalid. >> >> Quite, but that doesn't explain why >> >> !function(a){alert(a)}('ho'); >> +function(a){alert(a)}('ho'); >> -function(a){alert(a)}('ho'); >> >> ... do not throw an error. >> >> "syntactically invalid" is just "according to the rules", >> "throwing an error" is what should concern us in practice. > > Ok, so we'll try to simplify a bit: A wonderful story – thanks for telling, Scott. And a really fine explanation of the interaction of parsers and scanners (aka lexers/tokenizers). Actually, I would like to see the story in a FAQ note. Maybe chapter 4, Function, should be augmented by a section about "Why is there an operator before `function`?" (or similar), which explains the issue shortly, and links to the full story. Thoughts? -- Christoph M. Becker