Skip to content
Better HN
Top
New
Best
Ask
Show
Jobs
Search
⌘K
0 points
ZachSaucier
2y ago
0 comments
Share
Couldn't you do elementReference.foo = whateverTypeYouWant? No need to restrict things to just the data attribute.
This wouldn't work if you need to know the order of the properties.
undefined | Better HN
0 comments
default
newest
oldest
SSchick
2y ago
This generally doesn’t play nice with TS code bases and is generally considered an anti-pattern since there’s chances for collisions etc , you might get away using a unique symbol index but it’s still not good design.
rcfox
2y ago
I'm not sure about DOM elements, but tacking random new properties onto Javascript objects can cause them to become deoptimized by the runtime.
ZachSaucier
OP
2y ago
Any reference for this?
2 more replies
megous
2y ago
Chances for collisions are pretty much nil if you use some prefix standard will never use, like $.
el.$my_data = ...
And in practice it works just fine.
j
/
k
navigate · click thread line to collapse