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


Groups > comp.lang.javascript > #12658

Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06)

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!border1.nntp.ams.giganews.com!nntp.giganews.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="ISO-8859-1"
Message-ID <10328270.UdUkD2KWN8@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Tue, 13 Mar 2012 20:54:09 +0100
User-Agent KNode/4.4.11
Content-Transfer-Encoding 7Bit
Subject Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06)
Newsgroups comp.lang.javascript
References <4f063989$0$283$14726298@news.sunsite.dk> <h0gqg7lji6327vo8eeiuv71urmrvger83q@4ax.com> <jel6t0$8v3$1@speranza.aioe.org> <jfgjqf$48c$1@speranza.aioe.org>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 41
NNTP-Posting-Date 13 Mar 2012 20:54:10 CET
NNTP-Posting-Host 792e6091.newsspool2.arcor-online.net
X-Trace DXC=A=G]X7h60LRU6b:FjPaGjQA9EHlD;3YcR4Fo<]lROoRQ8kF<OcfhCO[S6]dJ=QET;QDZm8W4\YJN\b@mF9jNikdUXDB:cF9DlYVMCI61Ua?eMR
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:12658

Followups directed to: comp.lang.javascript

Show key headers only | View raw


J.R. wrote:

> J.R. wrote:
>> (function () {
>>   // ...
>> }());
>>
>> Notice the trailing semi-colon (;)
>>
> 
> Another way of doing the same is:
> 
> !function () {
>    // ...
> }();
> 
> It works because the logical NOT operator ( ! ) is telling the
> interpreter to treat function(){}() as an UnaryExpression, in
> conformance with ECMA-262 5th ed:
> 
> 11.4.9 Logical NOT Operator ( ! )
> The production UnaryExpression : ! UnaryExpression is evaluated as
> follows: 1. Let expr be the result of evaluating UnaryExpression.
> 2. Let oldValue be ToBoolean(GetValue(expr)).
> 3. If oldValue is true, return false.
> 4. Return true.
> 
> So the anonymous function expression will be called immediately after
> creation, and the result will be true.

The result of the /ExpressionStatement/ (and the program, if it is the last 
statement) will be `true' iff the function does not return a true-value.  
Otherwise it will be `false'.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

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


Thread

Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06) Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-01-11 08:54 +0100
  Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06) "J.R." <groups_jr-1@yahoo.com.br> - 2012-01-11 21:44 -0200
    Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06) Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-01-12 09:26 +0100
    Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06) "J.R." <groups_jr-1@yahoo.com.br> - 2012-01-22 07:10 -0200
      Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-13 20:54 +0100

csiph-web