Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Can somebody explain this code Date: Wed, 04 May 2016 05:51:40 +0200 Organization: PointedEars Software (PES) Lines: 48 Message-ID: <3332181.Nmlc57RfOh@PointedEars.de> References: <2380128.LjnWGdRavf@PointedEars.de> <3457976.2eFHA4iNFV@PointedEars.de> <2497856.AOaF6Xk2y9@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn NNTP-Posting-Host: 90.228.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: gwaiyur.mb-net.net 1462333901 30463 178.197.228.90 (4 May 2016 03:51:41 GMT) X-Complaints-To: abuse@open-news-network.org NNTP-Posting-Date: Wed, 4 May 2016 03:51:41 +0000 (UTC) User-Agent: KNode/4.14.2 Xref: csiph.com comp.lang.javascript:30388 Aleksandro wrote: > On 27/03/16 20:07, Thomas 'PointedEars' Lahn wrote: >> Aleksandro wrote: >>> On 27/03/16 17:44, Thomas 'PointedEars' Lahn wrote: >>>> Aleksandro wrote: >>>>> On 24/03/16 16:30, Thomas 'PointedEars' Lahn wrote: >>>>>> var myFunc; >>>>>> myFunc = function () { alert("This is my anonymous function"); }; >>>>>> >>>>>> (In that case, “myFunc” is assigned the “undefined” value first.) >>>>> Would the VM actually assign undefined first? I doubt it. >>>> On what grounds? >>> Well, there's a thing called optimization... you know... >> Although successive lines, they are not necessarily processed so. > > But they might. I am not convinced. There are at least four points that you are overlooking here: 1. It was an *example* demonstrating functional equivalence of lines of source code. 2. myFunc = function () { alert("This is my anonymous function"); }; var myFunc; is equivalent to the previous code, too. 3. There can be source code between declaration and assignment, and in the assignment, referring to the variable. The value of the variable has to be the “undefined” value then. 4. There is not only one virtual machine. It need not even *be* a *virtual* machine; for example, Google V8 JIT-compiles source code directly into machine code. Taking unnecessary risks based on wild guesses and wishful thinking is the mark of a wannabe. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.