I often fail at providing the real-world use case I am after ... 'cause it takes time ... so right now I am implementing the DOM, you read that correctly ... thousand nodes with potentially zero attributes is what I am after, for both memory constraints and logic sake, so that their element.attributes
NamedNodeMap thing doesn't need to exist for everything that doesn't need to access, or set, those attributes.
My example can then be re-written as such:
class Element {
static #attributes(element) {
return element.#attributes || (element.#attributes = new Map);
}
#attributes = null;
setAttribute(name, value) {
// note: the attribute is simplified for convenience in this thread
Element.#attributes(this).set(name, { name, value });
}
getAttribute(name) {
return this.#attributes?.get(name)?.value;
}
}
And so on ... so yeah, thousands easy new instances that won't need at all the following, as the following will create X thousands Map objects for no reason whatsoever:
class Element {
#attributes = new Map; // <- there!
}
Accordingly, am I still right that using a class private field, that "obviously" (in your opinions) shouldn't be named after the instance private field itself, is faster than attaching N private fields to each instance?
I always strive for best performance (with least RAM needed) and every of my libraries do too ... so that having a clear statement here from TC39 would help me shaping this new wonder too, thank you.
edit to be honest, the current state not aligned with globals (not privates) stinks for both engines and DX, but I am sure it's been discussed plenty already.