element-behaviors
element-behaviors copied to clipboard
Should element behaviors be accessible on elements directly, or in a global map?
For example, should it be
const el = document.querySelector('div')
// suppose el is <div has="foo bar baz">
el.behaviors.add('click-logger')
el.behaviors.remove('foo')
// now el is <div has="bar baz click-logger">
which means .behaviors
would exist on Element.prototype
, or should it be something like
const el = document.querySelector('div')
// suppose el is <div has="foo bar baz">
elementBehaviors.of(el).add('click-logger')
elementBehaviors.of(el).remove('baz')
// now el is <div has="bar baz click-logger">
It seems like a global map would be easier to optimize, rather than increasing the size of the prototype of all elements by default. ?
I think global is a good idea. This feature is also missing for custom elements .