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


Groups > comp.lang.javascript > #10153

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06)
Date Wed, 11 Jan 2012 21:44:37 -0200
Organization Aioe.org NNTP Server
Lines 41
Message-ID <jel6t0$8v3$1@speranza.aioe.org> (permalink)
References <4f063989$0$283$14726298@news.sunsite.dk> <h0gqg7lji6327vo8eeiuv71urmrvger83q@4ax.com>
NNTP-Posting-Host edb3lPNLwDIT/BKKc/Xuzw.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20111105 Thunderbird/8.0
X-Antivirus-Status Clean
X-Notice Filtered by postfilter v. 0.8.2
X-Antivirus avast! (VPS 120111-1, 01/11/2012), Outbound message
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:10153

Show key headers only | View raw


On 11/01/2012 05:54, Hans-Georg Michna wrote:
> On Fri, 06 Jan 2012 00:00:02 +0000, FAQ server wrote:
>
>> -----------------------------------------------------------------------
>> FAQ Topic - What is (function(){ /*...*/ })() ?
>> -----------------------------------------------------------------------
>>
>> This is an anonymous FunctionExpression that is called
>> immediately after creation.
>>
>> Variables declared inside a function are not accessible from
>> outside the function. This can be useful, for example, to hide
>> implementation details or to avoid polluting the global scope.
>>
>> <URL: http://yura.thinkweb2.com/named-function-expressions/>
>> <URL: http://jibbering.com/faq/notes/closures/>
>> <URL: http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses>
>>
>>
>> The complete comp.lang.javascript FAQ is at
>> http://jibbering.com/faq/
>
> It may be a good idea to mention that it is sometimes written
> as:
>
> (function(){ /*...*/ }())
>
> Note the different arrangement of the last parentheses.
>
> I believe this is functionally equivalent.

Besides, JSLint complains about any different form other than this:

(function () {
   // ...
}());

Notice the trailing semi-colon (;)

-- 
Joao Rodrigues (J.R.)

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


Thread

FAQ Topic - What is (function(){ /*...*/ })() ? (2012-01-06) "FAQ server" <javascript@dotinternet.be> - 2012-01-06 00:00 +0000
  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