- https://github.com/tc39/proposal-record-tuple
- https://github.com/tc39/proposal-deep-path-properties-for-re...
- https://github.com/tc39/proposal-record-tuple
- https://github.com/tc39/proposal-deep-path-properties-for-re...
CLJS: ¯\_(ツ)_/¯
And structuredClone was standardized to serialize objects passed between contexts.
So I don't see what's wrong with teaching people about this as the native way to clone serializable objects.
Record/Tuples are different types and I don't think that "what you really want" is a future proposal when you want a built-in now.
Misuse of deepClone & co is just a very common antipattern.
Or when working with libraries that demand this.
In that spirit, I find MobX pleasant to work with as an alternative.
Although it remains needed to grok reference equality checks in reactivity, there's no way around that I guess.
Fundamentally, when passing messages with structured payloads I'd consider it good style for the payload to be serializable and free from references and mutable state.
structuredClone, if I'm not mistaken also allows cloning functions/Maps/Sets, so while there may be some overlap, I'm not sure having Records and Tuples solves the same problems. Or as nerdy engineers are so prone to say, they're "orthogonal".
Map and Set yes, but not functions. Makes sense because there is no reasonable way to serialize functions in JS.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...
edit: I have no idea what actually happens to cloned maps with function values or keys though...
As an unrelated aside, recursive proxies would also be extremely useful
[0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
"instead of learning x, use y library" Sometimes that advise makes sense, yes. But it's constantly used in a dogmatic manner.
The goal of #-private properties in JS is to have total runtime isolation, so that there's no way at all to access it from the outside. If you're fine with a compile-time error, use TypeScript's private keyword instead (JS does not have a compiler).
But why can't `otherObj.abc = 3` throw an error if abc is declared as private? Because it would incur a runtime cost on all property accesses to check whether it's public or not, even if private properties aren't used anywhere within the class. Not a sacrifice anyone would be willing to make.
So, the solution is to make sure that private property accesses can be distinguished from public property accesses. You could have had something like `private.abc` instead of `this.#abc`. But I don't think that's better, either.
Honestly, you'll get used to # if you use it for a while.