# struct object sub-type

**URL:** https://es.discourse.group/t/struct-object-sub-type/2652
**Category:** 💡 Ideas
**Created:** [September 14, 2026, 9:29pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652 "2026-09-14T21:29:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)
#### Post date: [September 14, 2026, 9:29pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/1 "2026-09-14T21:29:06Z")

</div>

I propose the `Struct` class or the `struct` keyword.  
Any subclass of `Struct` or any `struct` class should be of the `struct` type and final, when the struct object exits the constructor it should be sealed, and have value semantics.

example:

```js
class Point extends Struct{
    x=0;
    y=0;
    constructor(x,y){
        this.x=x;
        this.y=y;
    }
}
//or
struct Point{
    x=0;
    y=0;
    constructor(x,y){
        this.x=x;
        this.y=y;
    }
}
assert(typeof new Point(0,0) === 'struct')
assert(new Point(0,0) === new Point(0,0))
assert(new Point(1,0) !== new Point(0,0))
new Point(0,0).z = 0; //fails

```

this will be a great tool for memory optimization in javascript

---

<div class="post-metadata">

### Author: ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)
#### Post date: [September 14, 2026, 9:43pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/2 "2026-09-14T21:43:58Z")

</div>

Proposals need to start with a problem to be solved - suggesting the solution is often inappropriate until the problem is understood and supported. What problem does this attempt solve?

Additionally, claims about optimization opportunities are often found to be (unintuitively) false by engine implementers, so I'd suggest avoiding such claims unless you are one. (i am not one either, to be clear)

---

<div class="post-metadata">

### Author: ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)
#### Post date: [September 14, 2026, 10:17pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/3 "2026-09-14T22:17:14Z")

</div>

it should just be a way to make objects be passed by value instead of by reference so that you don't have code accidentally modifying some object it shouldn't touch if the function was suppoded to copy just one value but you forgot to but it adds it.  
and to also decrease gc and memory access time

---

<div class="post-metadata">

### Author: ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)
#### Post date: [September 14, 2026, 10:30pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/4 "2026-09-14T22:30:40Z")

</div>

Currently at stage 2

> **[GitHub - tc39/proposal-structs: JavaScript Structs: Fixed Layout Objects](https://github.com/tc39/proposal-structs)**
>
> JavaScript Structs: Fixed Layout Objects

---

<div class="post-metadata">

### Author: ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)
#### Post date: [September 14, 2026, 10:41pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/5 "2026-09-14T22:41:03Z")

</div>

Everything in JS is pass by value, technically - it's just that objects are like a by-value pointer you can't avoid dereferencing. If you want an object to not be mutated, you can use Object.freeze() on it.

---

<div class="post-metadata">

### Author: ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)
#### Post date: [September 15, 2026, 9:54pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/6 "2026-09-15T21:54:30Z")

</div>

It would be nice to have value semantics on certain types of objects

---

<div class="post-metadata">

### Author: ![WebReflection](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/webreflection/32/248_2.png) [@WebReflection](https://es.discourse.group/u/WebReflection)
#### Post date: [September 16, 2026, 12:12pm UTC](https://es.discourse.group/t/struct-object-sub-type/2652/7 "2026-09-16T12:12:32Z")

</div>

any reason it got stuck at Stage 2 ??? it's been around for a while and it would be a great feature to have, especially the _SharedStruct_ part which might finally put an end to the SharedArrayBuffer madness [GitHub - tc39/proposal-structs: JavaScript Structs: Fixed Layout Objects · GitHub](https://github.com/tc39/proposal-structs#shared-structs)
