Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25488

Re: Images and pdf in a div

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Images and pdf in a div
Date 2014-07-21 02:00 +0200
Organization PointedEars Software (PES)
Message-ID <3966722.Cq8BDrRF97@PointedEars.de> (permalink)
References (3 earlier) <XnsA36FA164733A9eejj99@194.109.133.133> <lqe6fa$sid$1@dont-email.me> <m_CdnTCZ5NKWzlbOnZ2dnUVZ_tGdnZ2d@westnet.com.au> <2221038.iVyETpmlb9@PointedEars.de> <Zf2dnfu0HYh7olHOnZ2dnUVZ_gqdnZ2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> On 20/07/2014 8:42 PM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>>     var isInstalled = false,
>>>         vern = null;
>>>
>>>     function findPlugin(nme) {
>>>       var p;
>>>       for (key in navigator.plugins) {
>>
>> Do not use the for-in statement with host objects and array-like objects;
>> their properties may not be enumerable, not in a defined order or have
>> enumerable properties that you do not want to iterate over (like
>> “refresh”);
>> use the “for” statement instead.  Exception: Array instances known to
>> encapsulate a sparse array; in that case for-in is more efficient, and
>> you can filter and sort the properties later, if necessary.
> 
> How do I search through navigator.plugins using "for" instead of "for-in"?

  for (var i = 0, plugins = navigator.plugins, len = plugins.length;
       i < len; ++i)
  {
    … plugins[i] …
  }

(One of the properties you get when you use for-in is the “length” property 
from which you could have inferred that.)
 
>> “isInstalled” is superfluous because you can test against the value of
>> “plugin” instead, which would be either not “null” or not “undefined” if
>> successful, depending on how you initialize it.
> 
> After searching for "plugin" I set it to null to clear any memory...

Unnecessary if you do not return it, may even be harmful.
 
>> And “}())” instead in order to make clear what makes up the right-hand
>> side expression.  This will also become handy in editors like Vim or
>> Eclipse JSDT with Vrapper plugin, where, which I discovered yesterday,
>> you can type “vi)” to select everything between the outer parentheses,
>> for refactoring.
> 
> Ok,
> <http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses>
> says that both are correct so I just picked the first one.

Where you put the parantheses in this case is a matter of code style.

However, there are several factually wrong or misleading statements in that 
text.  I find it interesting that someone who has demonstrated here 
(approximately at the time of writing that article, or shortly after) that 
he neither understood ECMAScript nor that he was willing to learn, now 
thinks he can teach others about it.  I find it even more interesting that 
some people believe those statements as if he would be some kind of 
authority on the subject.

> Thanks for the advice.

You’re welcome.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-19 00:31 +0200
  Re: Images and pdf in a div "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-19 13:34 +0200
    Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-19 15:34 +0200
      Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-19 15:51 +0200
        Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-19 18:30 +0200
          Re: Images and pdf in a div Andrew Poulos <ap_prog@hotmail.com> - 2014-07-20 15:23 +1000
            Re: Images and pdf in a div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-20 12:42 +0200
              Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-20 20:07 +0200
                Re: Images and pdf in a div Andrew Poulos <ap_prog@hotmail.com> - 2014-07-21 14:10 +1000
                Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-21 14:19 +0200
              Re: Images and pdf in a div Andrew Poulos <ap_prog@hotmail.com> - 2014-07-21 08:14 +1000
                Re: Images and pdf in a div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-21 02:00 +0200
                Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-21 07:15 +0200
                Re: Images and pdf in a div Osmo Saarikumpu <osmo@weppipakki.com> - 2014-07-24 18:26 +0300
                Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-24 17:48 +0200
                Re: Images and pdf in a div Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-07-24 22:32 +0100
                Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-24 23:58 +0200
                Re: Images and pdf in a div "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-24 18:40 +0200
                Re: Images and pdf in a div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-25 12:31 +0200
                Re: Images and pdf in a div John Harris <niam@jghnorth.org.uk.invalid> - 2014-07-25 15:52 +0100

csiph-web