Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Can somebody explain this code Date: Thu, 24 Mar 2016 20:30:29 +0100 Organization: PointedEars Software (PES) Lines: 28 Message-ID: <2380128.LjnWGdRavf@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1458847830 20465 eJwNycEBwCAIA8CVCgYC4zRU9x/B3vdipeUQGYk4cVhKc2g3TPPmLohBG37urRLWvw+PIPn0BRU7EQA= (24 Mar 2016 19:30:30 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 24 Mar 2016 19:30:30 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNyckRwDAIBLCWgAU27cQc/ZdgPzUKpGbRM9JjY896h1s0lMb+USPa8olC57iXDvjYNGhugTwvzSc3B3IBPA0UhA== Cancel-Lock: sha1:ZH9Sfegu8Arrvsu5t/+zq35ZfNw= X-NNTP-Posting-Host: eJwNysEBwCAIA8CVsAlRxgHR/Uew9z6HhvakXPTrl0TWIirZvmSz/VikNYZVCHn++g20ojbUDw5FEJU= Xref: csiph.com comp.lang.javascript:30110 Tony Johansson wrote: > I know that functions behave much like variables such as > var myFunc = function() { alert("This is my anonymous function");} A misconception. Instead, the variable “myFunc” is being declared, and initialized with (i.e., being assigned as first value) a reference to an object, a Function instance. That object’s “name” property has the value "" (as inherited from the Function prototype object); it is an anonymous function as it was created with what is commonly called an “anonymous function expression” (AFE). [The right-hand side is equivalent to a “lambda” expression, e.g. in Python.] It is *functionally* equivalent to var myFunc; myFunc = function () { alert("This is my anonymous function"); }; (In that case, “myFunc” is assigned the “undefined” value first.) -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.