News for hackers. Stuff that matters.
Re:New ES2019 JavaScript features by lhorie on Thursday September 26, 2019 @05:53PM (#21085985)
FYI, the ES2019 spec has been published[1] already and optional chaining and pipeline operator are not in it.

If you want to know what's new in ES2019, look no further than the [Introduction](https://www.ecma-international.org/ecma-262/10.0/index.html#...) section in the spec.

> This specification, the 10th edition, introduces a few new built-in functions: flat and flatMap on Array.prototype for flattening arrays, Object.fromEntries for directly turning the return value of Object.entries into a new Object, and trimStart and trimEnd on String.prototype as better-named alternatives to the widely implemented but non-standard String.prototype.trimLeft and trimRight built-ins. In addition, this specification includes a few minor updates to syntax and semantics. Updated syntax includes optional catch binding parameters and allowing U+2028 (LINE SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR) in string literals to align with JSON. Other updates include requiring that Array.prototype.sort be a stable sort, requiring that JSON.stringify return well-formed UTF-8 regardless of input, and clarifying Function.prototype.toString by requiring that it either return the corresponding original source text or a standard placeholder.

[1] https://www.ecma-international.org/ecma-262/10.0/index.html

Re:New ES2019 JavaScript features by robotstate on Friday September 27, 2019 @01:24AM (#21088698)
Of course the two features I was most excited about aren't in the actual spec...
Re:New ES2019 JavaScript features by randallsquared on Thursday September 26, 2019 @05:53PM (#21085980)
This seems like a better guide to actual ES2019: https://medium.com/@selvaganesh93/javascript-whats-new-in-ec...
Re:New ES2019 JavaScript features by baron816 on Thursday September 26, 2019 @05:52PM (#21085971)
Why is the pipeline operator mentioned here? That’s definitely not ES2019.
Re:New ES2019 JavaScript features by SSchick on Thursday September 26, 2019 @06:55PM (#21086495)
Yea, I was thinking the same, it's not even on https://github.com/tc39/proposals
Re:New ES2019 JavaScript features by lhorie on Thursday September 26, 2019 @07:10PM (#21086617)
Stage 1 proposals were moved to a separate page, presumably to reduce clutter https://github.com/tc39/proposals/blob/master/stage-1-propos...
Re:New ES2019 JavaScript features by STRiDEX on Thursday September 26, 2019 @06:08PM (#21086109)
I always use http://node.green because it also tells me if I can use it yet/soon.
Re:New ES2019 JavaScript features by zaro on Friday September 27, 2019 @12:46AM (#21088529)
Thanks. I've wondered recently how to check what is supported in node.
Re:New ES2019 JavaScript features by crooked-v on Thursday September 26, 2019 @06:40PM (#21086370)
The pipe operator is the key thing I'm really looking forward to as a general quality of life improvement.
Re:New ES2019 JavaScript features by Bjartr on Thursday September 26, 2019 @07:08PM (#21086599)
Wait, trimLeft/trimRight has different semantics from trimStart/trimEnd in RTL languages. So it has to be more than a simple alias, right?
Re:New ES2019 JavaScript features by lioeters on Thursday September 26, 2019 @08:38PM (#21087300)
I checked on MDN:

"The trimStart() method removes whitespace from the beginning of a string. trimLeft() is an alias of this method."

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

I suspect that trimLeft was misnamed, since its "left" didn't take into account RTL - it just meant start of string.

Re:New ES2019 JavaScript features by dlojudice on Thursday September 26, 2019 @05:28PM (#21085737)
JS is going to be so different in 2019 that I'm expecting a revised version of "The Good Parts"[1]

[1] https://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockfo...

Re:New ES2019 JavaScript features by eropple on Thursday September 26, 2019 @06:59PM (#21086530)
That book is of an era and hasn't been particularly relevant in quite awhile. The rise of classes as prototype sugar made a lot of the navel-gazing of object creation mostly moot. The rise of rigorous linting took care of the rest.

TypeScript helped a lot, too.

Re:New ES2019 JavaScript features by Roboprog on Thursday September 26, 2019 @07:31PM (#21086793)
Some of us consider “class” a bad thing.

I would rather work in a language/style that draws its inspiration from Scheme than Simula 67.

Too bad more places are picking up TypeScript rather than ClosureScript.

Re:New ES2019 JavaScript features by orangecat on Thursday September 26, 2019 @08:01PM (#21087030)
I would rather work in a language/style that draws its inspiration from Scheme than Simula 67.

Then you should push for WebAssembly improvements so you can use whatever language you want. As long as JavaScript is a de facto requirement for web development it needs to be as approachable as possible to a wide developer audience, and that means looking more like Java than Lisp.

Re:New ES2019 JavaScript features by BigJono on Thursday September 26, 2019 @08:20PM (#21087165)
Or we could've considered it an opportunity to move people away from classical inheritance and towards something that's conceptually much simpler? (which both prototypal inheritance and functional programming are)
Re:New ES2019 JavaScript features by pjmlp on Friday September 27, 2019 @02:38AM (#21089084)
Yet all successful functional programming languages do support doing OOP as well.
Re:New ES2019 JavaScript features by boomlinde on Friday September 27, 2019 @05:03AM (#21089862)
JS is and always was prototype based. The class keyword is as far as I know just syntax sugar that creates a prototype chain and a new-able function that assigns the prototype to self.
Re:New ES2019 JavaScript features by jwalton on Friday September 27, 2019 @07:26AM (#21090668)
The '#privateVar' syntax means that classes are no longer simply syntax sugar, unfortunately.
Re:New ES2019 JavaScript features by eropple on Friday September 27, 2019 @09:49AM (#21091928)
Private variables could always be simulated with IIFEs. I'm pretty sure that's actually how TypeScript does it if you compile down low enough.
Re:New ES2019 JavaScript features by jcadam on Thursday September 26, 2019 @08:44PM (#21087343)
> and that means looking more like Java than Lisp.

No.

(No (No (No (No (No)))))

Re:New ES2019 JavaScript features by eropple on Thursday September 26, 2019 @09:35PM (#21087600)
You can consider it a bad thing, but 1) it's a really thin layer on top of prototypical inheritance, 2) it makes JavaScript more accessible to people who are used to conventional styles of language, and 3) it won, indisputably.

ClojureScript didn't win, and never had a chance to win, because it's written for the small minority of Clojure people. It wasn't written for the overwhelming majority of developers. TypeScript was. So sorry that the existence of those day-to-day programmers puts a crimp in your utopia, but, enh. Personally, I'm glad we have tools to make it easier to write libraries to help that majority be more productive and to make their code safer and more correct!

Re:New ES2019 JavaScript features by nine_k on Thursday September 26, 2019 @09:24PM (#21087559)
Classes are fine! Inheritance isn't. You can mostly avoid using it, though.

JS lacks homoiconicity and thus can't have a lot of nice things a Lisp dialect would, notably macros.

With what we've got, I have more hope on JS eventually migrating towards a (more) statically typed language with ML influence; typescript sort of leans towards it, slowly.

Re:New ES2019 JavaScript features by sli on Friday September 27, 2019 @12:15PM (#21093538)
You're right about Lisp features, but CLJS macros are kind of bad at the moment. I have a fairly simple macro that works just fine in Clojure but does not compile in ClojureScript and I can't figure out why. It's probably a side-effect of how macros are handled in CLJS (they're part of a different compilation stage and must be written in CLJ or CLJC, hence :require-macros instead of just :require).

If you're looking for an ML, check out ReasonML. It's really quite good, its output is quite good (and hotfix friendly), and its type system is far better than TypeScript's will ever be. Mostly because TS wants to stay close to JS. Too close, in my opinion.

Re:New ES2019 JavaScript features by sli on Friday September 27, 2019 @12:12PM (#21093508)
It really is a shame because ClojureScript is an absolute joy to work with. TypeScript and Javascript feel so incredibly tedious to write after using CLJS for a few months.

I would really love to move into PureScript as well, but I haven't quite wrapped my arms around Haskell as a whole, yet. So maybe I should tip my toes back into Elm for a bit.

Re:New ES2019 JavaScript features by jcadam on Thursday September 26, 2019 @08:36PM (#21087294)
I do not use the 'class' keyword in Javascript and I never will.

I mean, I don't like using it in Java either, but it isn't really optional there...

Re:New ES2019 JavaScript features by stevula on Friday September 27, 2019 @01:13PM (#21094054)
Not optional for React devs. Well... maybe now with hooks.
Re:New ES2019 JavaScript features by atonse on Thursday September 26, 2019 @06:24PM (#21086233)
As a former C# dev, I’m excited about the optionals.

As a current elixir dev, VERY excited about the pipe operator.

Re:New ES2019 JavaScript features by nojvek on Friday September 27, 2019 @01:40AM (#21088773)
Chaining operator is likely to land. V8 has optional support for it and Babel has some plugins.

Pipeline operator has lots of quirks and syntax bikeshedding. I don’t think it may land.

Especially when you can make your own pipe(x,y,z) function quite easily. Just a guess though.

Re:New ES2019 JavaScript features by rkwz on Thursday September 26, 2019 @09:26PM (#21087562)
I wish there was more focus on increasing the surface area of the standard library instead of more language features like Golang
Re:New ES2019 JavaScript features by 11235813213455 on Saturday September 28, 2019 @05:53AM (#21099454)
> pipeline operator

no thanks, I don't think it's an interesting feature, there are alternatives (chaining, promises, ..) to avoid the cost of this new syntax

Other proposals I'm more excited about:

- https://github.com/tc39/proposal-iterator-helpers

- https://github.com/tc39/proposal-slice-notation/ (and https://github.com/tc39/proposal-slice-notation/pull/32)

Re:New ES2019 JavaScript features by RobertKerans on Friday September 27, 2019 @08:14AM (#21090991)
This is a very minor frustration, and I'm screaming into the abyss, but when searching for JavaScript topics, blogposts from LogRocket pretty often come up top of the search rankings, above more authoritative sources. Often under slightly misleading titles (such as this one) that seem chosen to capitalise on common search terms, or else the articles are packed with keywords. Sometimes mildly useful but mostly they're shallow and not particularly contentful, and LogRocket seem to absolutely churn them out. Seems to have gone down slightly since moving from Medium to Hosted WP, but not much. Nothing doing, it's just SEO and getting the name "LogRocket" in front of more eyeballs, but just...urrgh
Re:New ES2019 JavaScript features by a13n on Thursday September 26, 2019 @07:11PM (#21086635)
Super duper excited about optional chaining!

One thing I miss from Objective-C that I wish JS would add is the `?:` operator – basically a shortened version of the ternary operator.

Re:New ES2019 JavaScript features by rmrfrmrf on Thursday September 26, 2019 @07:56PM (#21086984)
Optional chaining is moving through committee along with the "nullish coalescing operator" represented as `??`, which works like `||` except only falls through with `null` and `undefined`.
Re:New ES2019 JavaScript features by kamyarg on Thursday September 26, 2019 @08:03PM (#21087044)
Do you mean

    true ? console.log("foo") : console.log("bar")
?

This is already there: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:New ES2019 JavaScript features by robinson7d on Thursday September 26, 2019 @08:21PM (#21087166)
It’s more than simple ternary, for example: `response?.data?.users?[0]`

To get the first user from a server response would be significantly longer if you wrote three nested ternary operators.

Re:New ES2019 JavaScript features by james-mcelwain on Thursday September 26, 2019 @08:07PM (#21087073)

  x ?: y 
is shorthand for

  x != null ? x : y
Re:New ES2019 JavaScript features by jchook on Thursday September 26, 2019 @08:43PM (#21087338)
In JavaScript you can simply use the logical or operator

x || y

Re:New ES2019 JavaScript features by rimunroe on Thursday September 26, 2019 @08:54PM (#21087420)
This is not equivalent. It will result in y if x is any falsy value (like false, empty string, or 0), not just if x is nullish.
Re:New ES2019 JavaScript features by jchook on Friday September 27, 2019 @01:16AM (#21088670)
In which languages does ?: not work that way?

For example in PHP, it works exactly like you describe.

Re:New ES2019 JavaScript features by nojvek on Friday September 27, 2019 @01:43AM (#21088785)
I think that’s exactly what the nullish ?? Operator is.

You can write x ?? y

Which is x !== null and x != undefined ? x : y

Re:New ES2019 JavaScript features by james-mcelwain on Friday September 27, 2019 @11:42AM (#21093170)
Kotlin.
Re:New ES2019 JavaScript features by kamyarg on Thursday September 26, 2019 @08:15PM (#21087124)
Ah, thanks for the clarification. Did not know it is supported in some languages.
Re:New ES2019 JavaScript features by strbean on Thursday September 26, 2019 @07:48PM (#21086916)
How would this differ from the idiomatic "x || y"? Just s/non-zero/truthy
Re:New ES2019 JavaScript features by nojvek on Friday September 27, 2019 @01:44AM (#21088794)
|| short circuits on falsey. 0, “”, false, null, undefined

?? Short circuits on nullish. Only null and undefined.

Re:New ES2019 JavaScript features by saagarjha on Thursday September 26, 2019 @07:19PM (#21086705)
I think that's a GCC C extension, not an Objective-C feature.
Re:New ES2019 JavaScript features by a13n on Thursday September 26, 2019 @07:22PM (#21086737)
Sure, I still miss it from Objective-C :P
Re:New ES2019 JavaScript features by hpen on Thursday September 26, 2019 @09:14PM (#21087524)
woooh optional chaining!
Re:New ES2019 JavaScript features by Roboprog on Thursday September 26, 2019 @07:42PM (#21086864)
Thanks for links to accurate information, those who posted

TL;DR - most of what is added in 2019 I can already do with Ramda.js, and it works in IE11, as well.

Pity about the Ruby / Groovy style dot-condition-chaining NOT being in the 2019 features, though.