News for hackers. Stuff that matters.
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.
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-...

Re:JavaScript Temporal Is Coming by adabyron on Thursday January 30, 2025 @09:29PM (#42884225)
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.

Re:JavaScript Temporal Is Coming by recursive on Thursday January 30, 2025 @12:04PM (#42879704)
Assignment is already an expression, no?

    console.log(x = "hello");
Re:JavaScript Temporal Is Coming by 65 on Thursday January 30, 2025 @10:30PM (#42884479)
Now try it with a constant:

    console.log(const x = "hello");
Doesn't work.
Re:JavaScript Temporal Is Coming by recursive on Thursday January 30, 2025 @10:45PM (#42884531)
That's a declaration. That would be cool. Doesn't currently work with let or var either.
Re:JavaScript Temporal Is Coming by 65 on Friday January 31, 2025 @11:14AM (#42888950)
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 2
Re:JavaScript Temporal Is Coming by recursive on Friday January 31, 2025 @12:30PM (#42889628)
Only 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.
Re:JavaScript Temporal Is Coming by hajile on Thursday January 30, 2025 @10:18AM (#42878538)
I also REALLY want records and tuples.
Re:JavaScript Temporal Is Coming by DanielHB on Friday January 31, 2025 @08:51AM (#42887629)
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.