Live data from Hacker News

What’s New in ES2019

blog.tildeloop.com

71–80 of 411 posts

Re: What’s New in ES2019

#71
post #3

It's great to see JS getting some of the features of better planned languages. But I'm still very nervous about some of the stuff mentioned here with regard to mutation. Taking Rust and Clojure as references, you always know for sure whether or not a call to e.g. `flat` will result in a mutation. In JS, because of past experience, I'd never be completely confident that I wasn't mutating something by mistake. I don't…

I still don't understand why neither JSs var or let allow you to redefine the variable with the same name. I makes chaining things while debugging so much harder: let a = a.project(); let a = debug(a); let a = a.eject(); vs let a1 = a.project(); let a1d = debug(a1); let a2 = a1d.eject();

    let projected = a.project();
    let debugged = debug(projected);
    let ejected= debugged.eject();

Re: What’s New in ES2019

#72

Earlier quoted context omitted.

I still don't understand why neither JSs var or let allow you to redefine the variable with the same name. I makes chaining things while debugging so much harder: let a = a.project(); let a = debug(a); let a = a.eject(); vs let a1 = a.project(); let a1d = debug(a1); let a2 = a1d.eject();

let projected = a.project(); let debugged = debug(projected); let ejected= debugged.eject();

And you need to change 3 lines in total (also you need to make changes mid-lines, too) in order to simply view the data in between, vs only 1 line.

And by the way - if you paid attention in the first place my post actually has exactly what you've just written.

Re: What’s New in ES2019

#73

Earlier quoted context omitted.

I still don't understand why neither JSs var or let allow you to redefine the variable with the same name. I makes chaining things while debugging so much harder: let a = a.project(); let a = debug(a); let a = a.eject(); vs let a1 = a.project(); let a1d = debug(a1); let a2 = a1d.eject();

let a = a.project(); a = debug(a) a = a.eject(); This is perfectly legal.

So what's the point of having let, then?

Re: What’s New in ES2019

#74
post #3

It's great to see JS getting some of the features of better planned languages. But I'm still very nervous about some of the stuff mentioned here with regard to mutation. Taking Rust and Clojure as references, you always know for sure whether or not a call to e.g. `flat` will result in a mutation. In JS, because of past experience, I'd never be completely confident that I wasn't mutating something by mistake. I don't…

I still don't understand why neither JSs var or let allow you to redefine the variable with the same name. I makes chaining things while debugging so much harder: let a = a.project(); let a = debug(a); let a = a.eject(); vs let a1 = a.project(); let a1d = debug(a1); let a2 = a1d.eject();

If you use let it means you intend to use that binding "later", up to the end of the scope, and within that scope the value shall not change: that's the Whole point.

If you want a variable you can assign successive different values to, it's an entirely different thing, and there have always been var and the assignment operator for that.

Re: What’s New in ES2019

#75

Earlier quoted context omitted.

I still don't understand why neither JSs var or let allow you to redefine the variable with the same name. I makes chaining things while debugging so much harder: let a = a.project(); let a = debug(a); let a = a.eject(); vs let a1 = a.project(); let a1d = debug(a1); let a2 = a1d.eject();

If you use let it means you intend to use that binding "later", up to the end of the scope, and within that scope the value shall not change: that's the Whole point. If you want a variable you can assign successive different values to, it's an entirely different thing, and there have always been var and the assignment operator for that.

>> within that scope the value shall not change: that's the Whole point.

That's pure BS. This is only true for atomics, the value can change (under let, var and const) as we can easily see with Array.push, for example.

Re: What’s New in ES2019

#76
post #65

Why are empty elements in an array allowed? oO [1,2,,3]

Quite useful in situations such as:

> (str.match(regexWithGroup) || [, null])[1]

I.e. if the regex matches, then give me the first group (1st index) otherwise give me null.

Re: What’s New in ES2019

#77

Earlier quoted context omitted.

JS already has immutable objects with `Object.freeze()`. Personally I just use TypeScript which can enforce not mutating at compile time (for the most part).

Thanks. But can I then add and remove items from an immutable object to create new objects? Part of the immutable value proposition is being able to work with the objects. Based on [0] Freezing feels more like constant than immutable. And the 'frozenness' isn't communicated through the language - I could be passed a frozen or unfrozen object and I wouldn't know without inspecting it. And freeze isn't recursive agains…

Have you looked at Immer.js? It allows you to express modifications to immutable objects as a series of imperative operations.

In my experience most "immutability" in JS is enforced by convention or, at best, static type systems. It's not ideal, but it works.

Re: What’s New in ES2019

#78
That array.flat() and array.flatMap() stuff is great to see. Always having to rely on lodash and friends to do that type of work. Exciting to see how JS is evolving.

Re: What’s New in ES2019

#80

Can someone please point me to the rationale behind the new toString() function?

I don't know the answer to your question, but I would like to add to it to gain some clarity for myself: why not give the caller the option to have comments eliminated? An optional parameter `includeComments` bool with default `false` would provide backward compatibility while allowing those who need the comments to request them.
Post reply on HN