The whole thing is ripe for a redo. I know they get a lot of hate, but of all the big players in this space I think FB is the best equipped to do this in a way that doesn't ruin everything. I just wonder if they have an incentive (maybe trying to break the Google/MS hegemony on search?).
Named element IDs can be referenced as JavaScript globals
21–30 of 113 posts
Re: Named element IDs can be referenced as JavaScript globals
#22I don't want to sound like I have an axe to grind (but I do), but this is the kind of feature/wart that shows the age of the HTML/CSS/JS stack. The whole thing is ripe for a redo. I know they get a lot of hate, but of all the big players in this space I think FB is the best equipped to do this in a way that doesn't ruin everything. I just wonder if they have an incentive (maybe trying to break the Google/MS hegemony…
Re: Named element IDs can be referenced as JavaScript globals
#23I don't want to sound like I have an axe to grind (but I do), but this is the kind of feature/wart that shows the age of the HTML/CSS/JS stack. The whole thing is ripe for a redo. I know they get a lot of hate, but of all the big players in this space I think FB is the best equipped to do this in a way that doesn't ruin everything. I just wonder if they have an incentive (maybe trying to break the Google/MS hegemony…
The best equipped to do this are Google/MS/Apple because they actually control the source code of relevant contemporary browsers.
If FB could launch a browser on iOS that was in their walled garden, not only would it quickly receive wide adoption but it might become people's primary browser.
Not that I necessarily think that's a good thing, mind you.
Re: Named element IDs can be referenced as JavaScript globals
#24Now I'm worried of using IDs and finding issues with globals in JavaScript. Seems to be a curious issue to be debugged.
If you read the article and the spec, you'll see that any explicitly created variables will always take precedence over automatic IDs, so any globals will always override these IDs.
[1] https://css-tricks.com/named-element-ids-can-be-referenced-a...
Re: Named element IDs can be referenced as JavaScript globals
#25Earlier quoted context omitted.
The best equipped to do this are Google/MS/Apple because they actually control the source code of relevant contemporary browsers.
I think that this is the case (right now) because of Apple's stranglehold on the browser on iOS and the complex relationship between Google/Apple. If FB could launch a browser on iOS that was in their walled garden, not only would it quickly receive wide adoption but it might become people's primary browser. Not that I necessarily think that's a good thing, mind you.
Re: Named element IDs can be referenced as JavaScript globals
#26I saw this "shortcut" used in code snippets, on online JS/CSS/HTML editors like JSFiddle. It did not even occur to me this was part of JS spec, I thought the editor was generating code behind my back!
It has nothing to do with JS spec; it's part of the DOM as defined by the HTML spec.
Re: Named element IDs can be referenced as JavaScript globals
#27I believe it works because the global object ("globalThis") is the Window in either case; this is why JavaScript Modules can refer to "window" in the global scope without explicitly importing it.
cool
console.log(this); // Window
console.log(globalThis); // Window
console.log("script", cool.innerHTML); // script cool
console.log(this); // undefined
console.log(globalThis); // Window
console.log("module", cool.innerHTML); // module cool
This seems like a missed opportunity. JavaScript Modules should have been required to "import {window} from 'dom'" or something, clearing out its global namespace.Re: Named element IDs can be referenced as JavaScript globals
#28Another similar gotcha is that the global-scoped `name` variable must be a string. See https://developer.mozilla.org/en-US/docs/Web/API/Window/name for details. var name = true; typeof name; // "string", not "boolean" Luckily, this is not true within ES modules which you probably use most of the time anymway.
I must have never used "name" as a name for a global variable or just for ones that were strings.
Re: Named element IDs can be referenced as JavaScript globals
#29Earlier quoted context omitted.
I think that this is the case (right now) because of Apple's stranglehold on the browser on iOS and the complex relationship between Google/Apple. If FB could launch a browser on iOS that was in their walled garden, not only would it quickly receive wide adoption but it might become people's primary browser. Not that I necessarily think that's a good thing, mind you.
Why would it quickly receive any adoption? Of all of the behemoths, I would trust FB the least here. Not that I trust any of the other big players enough not to use Firefox everywhere I can.
If FB says "hey install this app," they will install it.
Re: Named element IDs can be referenced as JavaScript globals
#30Earlier quoted context omitted.
It's has been explained enough times. It's just that looking things up for yourself seems to have gone out of fashion.
That doesn’t help people who stumble upon this when searching for the problem. All the “look it up” response does is make sure the search results are a bunch of content saying “look it up”, which isn’t really that helpful.
This used to be done quite a lot in the early JS days when scope was kind of thrown out the window (no pun) and you just did whatever dirty thing you needed to in order to make a page work.