Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.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 16:52:09 +0100 Organization: Aioe.org NNTP Server Lines: 43 Message-ID: References: NNTP-Posting-Host: QzgQT3zhqqgxdAIPZAoL8A.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:17947 W dniu 2013-01-04 14:56, Gregor Kofler pisze: > Am 2013-01-04 14:29, Cezary Tomczyk meinte: >> 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. > > Of course. However, they are no longer private variables of this > function. If you need this variables only within this function scope, I > prefer to restrict their visibility. That's true. >>> >> - 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. > > Er...? Yes? Yes :-) -- Cezary Tomczyk http://www.ctomczyk.pl/