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 21:31:56 +0200 Organization: solani.org Lines: 28 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1431027108 11738 eJwNysEBwEAEBMCWDmtPykHov4Rk3uNGYV/QCV/fXhyIxYNivKOZqFEJ80py+6j/4djc7lbmBxYbEOw= (7 May 2015 19:31:48 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 7 May 2015 19:31:48 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 X-User-ID: eJwNyckBgEAIA8CW0CVByuEw/Zeg8x0cXpxwgg5B5u+kngaIezPdd6trA2Y61JKDfyppnREfIEkRFg== In-Reply-To: Cancel-Lock: sha1:3DTIyn/KJwIqQC0qGbZNRbsQuf8= X-NNTP-Posting-Host: eJwFwQkRADAIAzBLPKWAHI5t/iUsCadyEwwiXjxgUoaQvqxUdxfrLeRRu2LjKm3QOrdkfeMD8rgPog== Xref: csiph.com comp.lang.javascript:27556 Evertjan. wrote: > Joao Rodrigues wrote on 07 mei 2015 in > comp.lang.javascript: > >> An Immediately-Invoked Function Expression (IIFE) is usually written as: >> (function() { /* etc. */ })(); >> >> But we can use unary operators instead of the wrapping parentheses too, >> if we don't care about the return value of the IIFE: >> >> Even the void operator can be used: >> void function () { /*...*/ }(); > > Even nothing can be used, > the final parenteses with parameters work then too, > try: > > alert( function(a){alert(a)} ) // function(a){alert(a)} > // [no execution of the function here] That works, because the IIFE is parsed in an expression context. If the IIFE is placed where a statement is expected, that would be a syntax error. The whole point of using parens or an operator is to enforce an expression context. -- Christoph M. Becker