# "static \<expr\>" syntax

**URL:** <https://es.discourse.group/t/static-expr-syntax/1673>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [April 4, 2023, 1:04pm UTC](https://es.discourse.group/t/static-expr-syntax/1673 "2023-04-04T13:04:59Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![trusktr](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/trusktr/32/183_2.png) [@trusktr](https://es.discourse.group/u/trusktr)\
**Post date:** [September 24, 2024, 6:30am UTC](https://es.discourse.group/t/static-expr-syntax/1673/22 "2024-09-24T06:30:04Z")

</div>

> [@bergus](#):
>
> Why did you put the object in a separate module for no reason? I don't see much of a difference between
> 
> ```javascript
> export function foo() {
> return thing ?? static Object.freeze([]);
> }
> 
> ```
> 
> and
> 
> ```javascript
> 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:

- [Intercept class field get/set (without accessor on prototype) · Issue #530 · tc39/proposal-decorators · GitHub](https://github.com/tc39/proposal-decorators/issues/530)
- [Reactive/observable field without "accessor"? · Issue #478 · tc39/proposal-decorators · GitHub](https://github.com/tc39/proposal-decorators/issues/478#issuecomment-2370222601)

---

<div class="post-metadata">

**Author:** ![simonkcleung](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/simonkcleung/32/785_2.png) [@simonkcleung](https://es.discourse.group/u/simonkcleung)\
**Post date:** [September 24, 2024, 2:09pm UTC](https://es.discourse.group/t/static-expr-syntax/1673/23 "2024-09-24T14:09:23Z")

</div>

> [@blob](#):
>
> ```javascript
> console.assert(count.current == 3)
> 
> ```

How about if a static variable "length" defined, e.g.  
`static length = 10;`  
what should count.length be? the argument.length 0? or 10?

---

<div class="post-metadata">

**Author:** ![blob](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/blob/32/2230_2.png) [@blob](https://es.discourse.group/u/blob)\
**Post date:** [September 24, 2024, 3:03pm UTC](https://es.discourse.group/t/static-expr-syntax/1673/24 "2024-09-24T15:03:19Z")

</div>

Similarly, in classes you cannot have a static field named `prototype` or `constructor`. Simply disallowing, or not exposing the property is perfectly fine

[Previous page](https://es.discourse.group/t/static-expr-syntax/1673.md?page=1)
