JavaScript dos and donts @ Mu-An Chiou
Straightforward smart sensible advice that you can apply to any feature on a website.
If you ignore the slightly insulting and condescending clickbaity title, this is a handy run-down of eight browser features with good support:
addEventListener()
,scrollTo()
,setTimeout()
and setInterval()
,defaultChecked
property for checkboxes,normalize()
and wholeText
for strings of text,insertAdjacentElement()
and insertAdjacentText()
,event.detail
, andscrollHeight
and scrollWidth
.Straightforward smart sensible advice that you can apply to any feature on a website.
The paradigm shift that web development is entering hinges on the fact that while React was a key enabler of the Single-Page-App and Component era of the web, in practice it normally tends to result in extremely poor products. Built-in browser APIs are now much more capable than they were when React was first invented.
This looks interesting. On the hand, it’s yet another proprietary creation by one browser vendor (boo!), but on the other hand it’s a declarative API with no JavaScript required (yay!).
Even if this particular feature doesn’t work out, I hope that this is the start of a trend for declarative access to browser features.
With classes, we can send CSS static values but with custom properties we can send dynamic ones, which is a major shift in the way we can style state. This is something that has been true for some time—and is extremely well supported—but sometimes it takes solving a small real-world problem to make you appreciate the value of it.
I think we still haven’t come to fully appreciate the superpower of custom properties: dynamic values that are shared between CSS and JavaScript.
Every word of this is spot on!
I’m also very grateful to Chris for taking the time and energy to write this — a perfect example of Brandolini’s law in action.
You might want to use `display: contents` …maybe.
Trying to understand a different mindset to mine.
Also, tipblogging.
If the JavaScript API requires a user gesture, maybe it’s time for a new button type.
Debugging an error message.