Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18019
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="UTF-8" |
| Message-ID | <1718550.E62eDaYUNW@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <usenet@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Tue, 08 Jan 2013 12:35:29 +0100 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 8Bit |
| Subject | Re: Two versions of code - advantages and differences |
| Newsgroups | comp.lang.javascript |
| References | <kc4uud$fam$1@speranza.aioe.org> <1512443.gQHv90F1im@PointedEars.de> <kccqct$ksk$1@speranza.aioe.org> <1603326.gHQpjbgioL@PointedEars.de> <kcfgto$4hj$1@speranza.aioe.org> |
| Followup-To | comp.lang.javascript |
| MIME-Version | 1.0 |
| Lines | 79 |
| NNTP-Posting-Date | 08 Jan 2013 12:35:29 CET |
| NNTP-Posting-Host | 39efd3a3.newsspool3.arcor-online.net |
| X-Trace | DXC=]eiY5Rm9C7K[6=1B@oB@@@McF=Q^Z^V3H4Fo<]lROoRA8kF<OcfhCOKe1h`^Sj[7oNDZm8W4\YJNLb@mF9jNikdE3>YBYU3JEoM:]c;j=1VF>M |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:18019 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
Cezary Tomczyk wrote:
> W dniu 2013-01-07 04:36, Thomas 'PointedEars' Lahn pisze:
>> Cezary Tomczyk wrote:
> [...]
>>>> Cezary Tomczyk wrote:
> [...]
>>>>> Version 1
>>>>>
>>>>> var el = document.getElementById('test');
>>>>> var fn = function(){
>>>>> if( !el ){
>>>>> // fallback if el is not available and then return
>>>>> }
>>>>> return el;
>>>>> };
>>>>>
>>>>> Version 2
>>>>>
>>>>> var fn = (function(){
>>>>> var el = document.getElementById('test');
>>>>>
>>>>> if(el){
>>>>> return function(){
>>>>> return el;
>>>>> }
>>>>> } else {
>>>>> // fallback if el is not available and then return
>>>>> }
>>>>> }());
> [...]
>
>>>> Static code analysis has a hard(er) time recognizing that “fn” actually
>>>> refers to a function in Version 2. AFAIK, the JSDoc Toolkit cannot
>>>> deal with it at all (but my JSdoc is going to).
>>> True, but they are two different examples.
>> Your point being?
>
> I was thinking that even if the functions are different then variable
> name is the same. I thought that JSdoc will catch this, but this doesn't
> make sense. When both of functions will be used in the same scope then
> Version 2 will overwrite Version 1.
Not all functions need be documented, so a documentor should consider the
documentation for a function to be finished when it sees the next “function”
keyword at the same nesting level. However, an exception needs to be made
for extra closures, because the outer function that returns the actual
function is not the function, and its parameter list does not contain the
parameters, that you usually want to document. Yet the identifier is
assigned the return value of that outer function, and you do want to
document the identifier if it is globally available or forced by the
developer to be documented.
>> Your code does not make sense to me at all, regardless of possible
>> inefficiencies. You are creating on initialization an ”img” object only
>> to clone it non-recursively (assuming this works) when the returned
>> function is called only to skip the “width” and “height” assignment –
>> seriously?
>
> I made a test and seems that creating once img node with properties and
> clone them later every time is faster than creating new img node and
> adding new properties. Just a small optimization.
Even if that was so (never trust benchmarks), it adds a dependency on
Node::cloneNode().
>> […] it escapes me here why you would want to insert
>> the equivalent of “ ” before and after the image; this should be
>> done with the “margin” CSS property instead.)
>
> Tried to use CSS, but it doesn't work for img. See:
> http://jsfiddle.net/w7BAu/
>
> Tested on Firefox 17.0.1 and IE9 (Windows 7, 64 bit).
AISB, use the “margin” property.
--
PointedEars
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-03 22:58 +0100
Re: Two versions of code - advantages and differences Stefan Weiss <krewecherl@gmail.com> - 2013-01-04 00:41 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-04 09:15 +0100
Re: Two versions of code - advantages and differences Gregor Kofler <usenet@gregorkofler.com> - 2013-01-04 11:26 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-04 14:29 +0100
Re: Two versions of code - advantages and differences Gregor Kofler <usenet@gregorkofler.com> - 2013-01-04 14:56 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-04 16:52 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-04 09:19 +0100
Re: Two versions of code - advantages and differences Gregor Kofler <usenet@gregorkofler.com> - 2013-01-04 11:25 +0100
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-04 15:31 +0100
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 08:37 -0800
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-05 18:14 +0100
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 10:51 -0800
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-05 20:46 +0100
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 17:12 -0800
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-06 17:43 -0800
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-07 03:58 +0100
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-06 19:23 -0800
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-07 05:19 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-06 22:30 +0100
Re: Two versions of code - advantages and differences Stefan Weiss <krewecherl@gmail.com> - 2013-01-07 02:35 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-07 22:45 +0100
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-07 04:36 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-07 23:06 +0100
Re: Two versions of code - advantages and differences Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-08 12:35 +0100
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-09 08:34 +0100
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 09:13 -0800
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-06 11:09 +0100
Re: Two versions of code - advantages and differences David Mark <dmark.cinsoft@gmail.com> - 2013-01-06 12:56 -0800
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-07 22:53 +0100
Re: Two versions of code - advantages and differences Luc Yen <luc@goal.tw> - 2013-01-05 12:54 -0800
Re: Two versions of code - advantages and differences Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-06 21:38 +0100
csiph-web