top | item 47137267

(no title)

post-it | 5 days ago

> you would eliminate all usage of innerHTML

The mythical refactor where all deprecated code is replaced with modern code. I'm not sure it has ever happened.

I don't have an alternative of course, adding new methods while keeping the old ones is the only way to edit an append-only standard like the web.

discuss

order

thenewnewguy|5 days ago

If you want to adopt this in your project, you can add a linter that explicitly bans innerHTML (and then go fix the issues it finds). Obviously Mozilla cannot magically fix the code of every website on the web but the tools exist for _your_ website.

Vinnl|5 days ago

I kinda like the way JS evolved into a modern language, where essentially ~everyone uses a linter that e.g. prevents the use of `var`. Sure, it's technically still in the language, but it's almost never used anymore.

(Assuming transpilers have stopped outputting it, which I'm not confident about.)

thunderfork|5 days ago

Depending on the transpiler and mode of operation, `var` is sometimes emitted.

For example, esbuild will emit var when targeting ESM, for performance and minification reasons. Because ESM has its own inherent scope barrier, this is fine, but it won't apply the same optimizations when targeting (e.g.) IIFE, because it's not fine in that context.

https://github.com/evanw/esbuild/issues/1301

delaminator|5 days ago

for some values of "everyone" and "never".

plorkyeran|5 days ago

I touch JS that uses var heavily on a daily basis and I would be incredibly surprised to find out that I am alone in that.

bulbar|5 days ago

It for sure happens for drop in replacements.

littlestymaar|5 days ago

Nobody's talking about old code here.

Having an alternative to innerHTML means you can ban it from new code through linting.

noduerme|5 days ago

Finally, a good use case for AI.

Aachen|5 days ago

Yeah, using a kilowatt GPU for string replacement is going to be the killer feature. I probably shouldn't even be joking, people are using it like this already

josefx|5 days ago

Wouldn't AI be trained on data using innerHTML?