Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Cezary Tomczyk Newsgroups: comp.lang.javascript Subject: Re: Two versions of code - advantages and differences Date: Fri, 04 Jan 2013 14:29:24 +0100 Organization: Aioe.org NNTP Server Lines: 43 Message-ID: References: NNTP-Posting-Host: LQb3dPuIOlzVtfLNj1CBlQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:17943 W dniu 2013-01-04 11:26, Gregor Kofler pisze: > > Am 2013-01-04 09:15, Cezary Tomczyk meinte: > > W dniu 2013-01-04 00:41, Stefan Weiss pisze: [...] > >> - When the function performs something computationally expensive (or > >> taking a long time), the result will be "remembered" and available for > >> subsequent calls to 'fn'. > > > > But same can be done in Version 1. > > At the cost of requiring more non-private variables. Well, they can be private if higher there is also closure. > >> - When, depending on the availability of 'el', two different functions > >> will be returned. > > > > That's true, but this can be done also in Version 1. Functions can be > > defined and returned. > > When you start returning functions, then you end up with version 2. But the Version 2 can be used when I want to use some variables inside and I am not sure if in the higher scope there is no same variable name. With all others I agree with you. [...] > >> Some people recommend to always use function expressions, but IMO, if > >> you know how variable and function declarations are handled when an > >> execution context is entered, this is unnecessary in most cases. > > > > You mean this? > > http://stackoverflow.com/a/3344397 > > As long as you understand the differences between the two you can use > both (or prefer whatever meets your personal preference). I agree. -- Cezary Tomczyk http://www.ctomczyk.pl/