trusktr
September 24, 2024, 6:30am
22
bergus:
Why did you put the object in a separate module for no reason? I don't see much of a difference between
export function foo() {
return thing ?? static Object.freeze([]);
}
and
const defaultArray = Object.freeze([]);
export function foo() {
return thing ?? defaultArray;
}
You were talking about globals, so I put it in a module to make it "global" (although, needs to be imported), to show the use case.
But even in the same file, then the module scope is polluted.
The beauty of static
is that there's no pollution at all.
Yeah, we can do the same as static
without static
. I'm just agreeing with others that it would be nice.
I argue that static
variables are not.
Especially for React code where having things inline is very very common.
Maybe there are bigger fish to fry. For example, I would absolutely much rather get these issues fixed regarding decorators:
How about if a static variable "length" defined, e.g.
static length = 10;
what should count.length be? the argument.length 0? or 10?
blob
September 24, 2024, 3:03pm
24
Similarly, in classes you cannot have a static field named prototype
or constructor
. Simply disallowing, or not exposing the property is perfectly fine