Skip to content
Better HN
Top
Best
Ask
Show
New
Jobs
Search
⌘K
0 points
ZachSaucier
3y ago
0 comments
Save
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.
0 comments
4 comments · 1 top-level
top
newest
oldest
SSchick
3y ago
· 3 in thread
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
3y 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
3y ago
Any reference for this?
2 more replies
megous
3y 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