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


Groups > comp.lang.javascript > #34752

Re: What's wrong with using a global id?

From Jon Ribbens <jon+usenet@unequivocal.eu>
Newsgroups comp.lang.javascript
Subject Re: What's wrong with using a global id?
Date 2018-02-26 15:18 +0000
Organization A noiseless patient Spider
Message-ID <slrnp9899v.31p.jon+usenet@sable.unequivocal.eu> (permalink)
References <global-ids-20180225051010@ram.dialup.fu-berlin.de> <1ec3czl2mmgku$.y2l7ncexmwul$.dlg@40tude.net> <1593727.VLH7GnMWUR@PointedEars.de>

Show all headers | View raw


On 2018-02-25, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> JJ wrote:
>> As long as there's a variable exist in the global context before the HTML
>> element is added into the HTML document, the HTML element ID will never
>> replace the existing variable.
>
> The order does not matter at all.

What do you mean by that? What JJ said there appears to be true,
and of course gives the reason why relying on window[id] is a bad
idea - because you don't know what different browsers or future
browser versions already have in the window object and therefore
you don't know whether window[id] will be your HTML element or
something else entirely.

  > var n = document.createElement("span")
  > n.setAttribute("id", "randomstring")
  > document.getElementsByTagName("body")[0].appendChild(n)
  > console.log(window.randomstring)

    <span id="randomstring"></span>

  > var n2 = document.createElement("span")
  > n2.setAttribute("id", "otherrandomstring")
  > window.otherrandomstring = 1
  > document.getElementsByTagName("body")[0].appendChild(n2)
  > <span id="otherrandomstring"></span>
  > console.log(window.otherrandomstring)

    1

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


Thread

Re: What's wrong with using a global id? JJ <jj4public@vfemail.net> - 2018-02-25 22:20 +0700
  Re: What's wrong with using a global id? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-02-25 17:37 +0100
    Re: What's wrong with using a global id? Julio Di Egidio <julio@diegidio.name> - 2018-02-25 09:16 -0800
      Re: What's wrong with using a global id? Julio Di Egidio <julio@diegidio.name> - 2018-02-25 10:19 -0800
    Re: What's wrong with using a global id? Jon Ribbens <jon+usenet@unequivocal.eu> - 2018-02-26 15:18 +0000
      Re: What's wrong with using a global id? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-03-02 17:06 +0100

csiph-web