Re:JavaScript Temporal Is Coming
by dkdbejwi383 on Thursday January 30, 2025 @08:32AM
(#42877505)
The one I want is pattern matching (https://tc39.es/proposal-pattern-matching/), which is still at stage 1 so many years away, sadly.
[ Parent
| on HN ]
Re:JavaScript Temporal Is Coming
by halfmatthalfcat on Thursday January 30, 2025 @09:31AM
(#42878029)
Pattern matching (and expression based assignment, of which idk if there’s a proposal for or not) are two things that would really drive a ton of value.
Re:JavaScript Temporal Is Coming
by CharlieDigital on Thursday January 30, 2025 @09:44AM
(#42878175)
It's going to end up looking a lot like C# [0][1]; these two/three (JS/TS, C#) languages have been converging for a while now. Now just waiting for C# to get official first party discriminated unions!
[0] https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
[1] https://timdeschryver.dev/blog/pattern-matching-examples-in-...
Just an FYI for those unaware TS & C# are both creations of Anders Hejlsberg & his colleagues at Microsoft. Both are some of my favorite languages as well.
We would all benefit if JS was more like C# in my opinion.
Assignment is already an expression, no?
console.log(x = "hello");Now try it with a constant:
console.log(const x = "hello");
Doesn't work.That's a declaration. That would be cool. Doesn't currently work with let or var either.
I think this is basically assigning values to the window object, similar to updating values in any object.
e.g.
const a = { b: 1 }
console.log(a.b = 2); // logs 2Only if you haven't already declared the variable. e.g.
let x;
console.log(x = 'hello');
My point is that the `x = 'hello'` part is an assignment, and an expression, and has the exact same semantics regardless of whether you use that expression as a statement. So, assignments would seem to be expressions.I also REALLY want records and tuples.
Unfortunately that proposal seems to be kinda dead.
React is a fundamentally flawed framework because of the lack of this feature. It inverts the responsibility of any non-primitive prop by putting the burden on the parent element instead of the child to decide when to rerender things. So elements are no longer self-contained if they receive any non-primitive values (besides react elements).
The React compiler auto-memoization that facebook is pushing also addresses this issue through build-time magic. I not fond of this approach.