Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34751
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: What's wrong with using a global id? |
| Date | 2018-02-26 14:35 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2186336.jE0xQCEvom@PointedEars.de> (permalink) |
| References | <global-ids-20180225051010@ram.dialup.fu-berlin.de> <id-20180225194506@ram.dialup.fu-berlin.de> <1653812.atdPhlSkOF@PointedEars.de> |
Thomas 'PointedEars' Lahn wrote:
> By having an element with ID “null” inserted and parsed in the HTML
> document, the global object provides access to the object representing
> that element in the document tree (an “element object” implementing the
> Element interface of W3C DOM 4, through an element-type specific interface
> – here, the HTMLParagraphElement interface) via property access to a
> property named “null”.
>
> Note that this wording, although more complicated, is important: it does
> _not_ imply that the global object actually has a property with that name.
> And indeed, using Object.getOwnPropertyNames(this).indexOf("null") in
> Firefox 52 (navigator.userAgent === "Mozilla/5.0 (X11; Linux x86_64;
> rv:52.0) Gecko/20100101 Firefox/52.0") one can show that it does not, and
> neither has one of the objects in its prototype chain
> (“Object.getPrototypeOf(this)” aso.)
One can now (ES 2015+) construct such an object using Proxy:
var proxy = new Proxy({
Array: Array
}, {
get: function (target, name) {
return (name in target)
? target[name]
: document.getElementById(name);
}
});
/* “[object Array]” (in all cases) */
console.log(proxy.Array);
/* “[object HTMLParagraphElement]” (in this case) */
console.log(proxy.null);
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | 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
Re: What's wrong with using a global id? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-02-26 14:30 +0100
Re: What's wrong with using a global id? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-02-26 14:35 +0100
Re: What's wrong with using a global id? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-03-02 15:05 +0100
Re: What's wrong with using a global id? John G Harris <niam@jghnorth.org.uk.invalid> - 2018-02-26 20:11 +0000
csiph-web