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


Groups > comp.lang.javascript > #28285

Re: Best way to show create different elements dynamically

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Best way to show create different elements dynamically
Date 2015-07-05 16:03 +0200
Organization PointedEars Software (PES)
Message-ID <33401923.tZnueLQKRv@PointedEars.de> (permalink)
References (2 earlier) <mnaomg$l33$1@dont-email.me> <359025142.IYVrofH7X8@PointedEars.de> <mnau4c$5dg$1@dont-email.me> <5889831.4kO5l0emlv@PointedEars.de> <mnb8t3$9ie$1@dont-email.me>

Show all headers | View raw


danca wrote:

> Il 07/05/2015 01:16 PM, Thomas 'PointedEars' Lahn ha scritto:
>> Also, you should always guard against the possibility that the element
>> object could not be created:
>>
>>    var aDiv = document.createElement("div");
>>    if (aDiv)
>>    {
>>      aDiv.style.position = "fixed";
>>    }
>>
> 
> Just a curiosity: this has to do with feature testing or with the
> possibilty that the element can not be created for some other reasons?

Were it for feature-testing, you would also test the 
document.createElement() method before you call it, not only its return 
value.

> In other words... are you aware of conditions that can reasonably cause
> createElement() to fail [if implemented]?

Good question.  Yes, this is a factory method; instantiation of an object 
can fail for various reasons.

However, it should be noted that none of W3C DOM Core Level 1, W3C DOM Level 
2 Core, W3C DOM Level 3 Core, W3C HTML5, and WHATWG HTML fully specifies 
what should happen in this case.  HTML5/WHATWG HTML only implicitly 
specifies that an interface for an unknown element type should be used if 
the element type name is unsupported, which is precisely what happens in 
HTML5 browsers [they use HTMLUnknownElement].

In particular, it is _not_ specified, contrary to what I previously thought, 
that the document.createElement() method could return a “null” value if it 
does not throw an exception.  And it is specified that it only shall throw 
exceptions if the specified element type name contains an “invalid” or 
“illegal character”:

<http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#i-Document>
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document>
<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-2141741547>
<http://www.w3.org/TR/2015/WD-dom-20150618/#dom-document-createelement>
<http://www.w3.org/TR/html5/dom.html#htmlunknownelement>
<https://html.spec.whatwg.org/multipage/dom.html#htmlunknownelement>

But it stands to reason that, without exceptions, the return value for 
failure would be a value that the ToBoolean() algorithm that is used by the 
“if“ statement converts to the “false” value (which I prefer to call “a 
false-value” for short).  So I think this test is still justified.
 
>>>> <http://www.quirksmode.org/dom/innerhtml.html>
>>>
>>> Interesting. Anyway, I was not concerned by any means about performance.
>>> And that page should be updated, it is really old stuff.
>>
>> There is a pseudo-link attached to each benchmark which you can run.  I
>> have run the tests 5 times each in Chromium “43.0.2357.130 Built on
>> Debian stretch/sid, running on Debian stretch/sid (64-bit)”.  The 
>> “innerHTML” approach to building tables is still the fastest one there.
> 
> Tried on Firefox 29 on Kernel 2.6.37.6 (Slackware 13.37/64) - best

You should say _Linux_ 2.6.37.6.  There are many kernels.

> result on last option, concatenate array.

Interesting.  I can confirm your observations in Iceweasel 38.0.1 on Debian 
GNU/Linux stretch/sid with Linux 3.16.0-4-amd64 (stock kernel).  However, it 
appears that *there* the runtime efficiencies of the two “innerHTML” 
approaches are so close that sometimes one is the faster one, then the 
other.

Have you also tested each approach 5 times in random order?

> And 180 msec vs 100 msec is the overall difference between fastest vs. 
> slowest method.

Even a difference of 80 milliseconds becomes significant if the algorithm 
taking 80 milliseconds longer than another one is repeated.

>> Please get a *real* name.
>
> For a human, ynnadrebyc can be understood as a childish way to protect
> my mail account from the spam, for a bot it can be puzzling [I hope].

Your hope is unfounded.

> [One sidenote: why the hell you insist on real names? Are you immune by
> spam?]

Posting using a pseudonym does not affect the amount of spam one is getting.
How did you get that idea?  Spam is sent to mailboxes referenced by *e-mail 
addresses*; not to specific people.  To use an analogy: if you remove your 
name from your real-life mailbox, or put a false name on it, that does not 
change the location of your home.

There is no good reason to believe that posting with a real name increases 
the amount of spam one is getting.  It does increase, however, the amount of 
people who can take you seriously.

-- 
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 | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 01:02 +0100
  Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 01:06 +0100
    Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 09:27 +0200
      Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:04 +0100
    Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 10:10 +0200
      Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 10:22 +0200
        Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 11:43 +0200
          Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 13:16 +0200
            Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 12:48 +0100
            Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 14:47 +0200
              Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 16:03 +0200
                Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 19:53 +0200
                Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-06 01:46 +0200
                Re: Best way to show create different elements dynamically "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-06 07:29 +0200
        Re: Best way to show create different elements dynamically Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2015-07-05 13:17 +0200
    Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 10:38 +0200
      Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:01 +0100
      Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:11 +0100
        Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 11:17 +0200
        Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 11:26 +0200
          Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:30 +0100
          Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:33 +0100
            Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 12:29 +0200
              Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 12:38 +0200
                Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 17:33 +0200
                Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 18:55 +0200
                Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 19:44 +0200
                Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 20:42 +0200
                Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 21:01 +0200
              Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 13:00 +0100
                Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 16:13 +0200
                Re: Best way to show create different elements dynamically Tim Streater <timstreater@greenbee.net> - 2015-07-05 15:23 +0100
                Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 15:57 +0100
  Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:03 +0100

csiph-web