Live data from Hacker News

What's New in JavaScript for 2019

developer.okta.com

21–30 of 85 posts

Re: What's New in JavaScript for 2019

#21

> There are a number of proposed changes to Classes, including field declarations, private methods and fields, and static methods and fields. So make it look full on like traditional OOP with classes, I guess? I suppose the prototype folks lost this debate.

It is interesting there is so much push towards classes now when a big part of the ecosystem (react) is moving away from them with react hooks.

Re: What's New in JavaScript for 2019

#22
I tend to agree with the article author about the use of a # (or indeed any punctuation mark) for private fields. I think it is just a personal preference thing though. Is there any publicly available discussion that shows what lead to this decision?

If fields in class definitions are incorporated I would like it to simultaneously make the field names in scope for any methods within the class definition.

  class Fish extends Vertebrate {
    color = "blue";
    constructor (speed) {
      super();
      this.speed = speed;  
      if (speed > 5) color = "red" // does not need this.color because color is a class field.
    }
  }

  Fish.prototype.setColor = function (newValue) {
     this.color = newValue;  // this. is required because this function is outside the class definition.
  }
Adding this feature would allow for much tidier method bodies since there is now enough information to imply this.fieldName from fieldName alone.

Re: What's New in JavaScript for 2019

#25
post #16

I'm alerted that javascript tends to bloat the stdlib. Most of the features mentioned can be implmented as a external library. This is benefitial for users as they can switch the implenmentation and upgrade versions without waiting for all of their users to upgrade the runtime first. The prime example of javascript unnecessary bloat is fetch api which is mere wrapper for ajax calls, was developed a while ago but stil…

I, on the other hand, am happy with this. It means not depending on a 3rd party (whose motivation or trustworthiness may fluctuate), it's easier to re-use code form other projects, and we don't have to worry about "what version of .each are we using?"

I do believe your concerns are still real ones, however. Fortunately, we can poly-fill.

Re: What's New in JavaScript for 2019

#26

I might get heat for this but personally I find the JavaScript ecosystem to be a mess. There are so many changes to the language that are done aggressively which I think are done without much thought. For example, the promises API, now we also have async/await. The module system, with require(s), then import/export, and there's browser JS and system JS (node), and npm and now yarn, then your build system, with webpac…

if we’re here, i’ve got a rant about npm. if you have more than a few dependencies, you need to download half of the internet for all the required 3rd party packages. this has security implications too, as i see no way to be able to watch them all, even with a local mirror

@downvoters: do you care to add a reply? it’s silly that instead of having a conversation, we’re doing this.

Re: What's New in JavaScript for 2019

#27
`flat` and `flatMap` are highly welcome additions for me; concatenating a bunch of lists together has historically been a very common operation for me, that right now is done best as

    [].concat(...arrayOfArrays)
It is also the basis more generally for the list monad, where `.flat()` is the `join` operation and `.flatMap()` is the equivalent `bind` operation.

So, like, the simplest example is if you're just getting a bunch of results from a paginated source -- you want to flatten them, and it is really nice to just have a method for that.

The list monad case is more interesting because it gives a syntax for list comprehensions:

    [ x + y for x in list1 for y in list2 if x % 2 == 0 and y % 2 == 1 ]
becomes

    list1.flatMap(x =>
      x % 2 !== 0 ? [] : list2.flatMap(y => (y % 2 == 0 ? [] : x + y))
    );
And more theoretically this list monad is all about composing nondeterminism, where one input could produce any of N outputs: if you store all of the current possibilities as an array then flatMap is the core composition primitive.

Re: What's New in JavaScript for 2019

#28

I might get heat for this but personally I find the JavaScript ecosystem to be a mess. There are so many changes to the language that are done aggressively which I think are done without much thought. For example, the promises API, now we also have async/await. The module system, with require(s), then import/export, and there's browser JS and system JS (node), and npm and now yarn, then your build system, with webpac…

All of these bits and pieces were built for good reason, it's nice to see them grow organically in different directions but able to borrow concepts from each other or collapsing down (as happened with Node and IOjs).

As a beginner it's a far more daunting picture, compared to Rails for example, but as a practitioner I'd like to build my project with pieces suited for purpose.

Re: What's New in JavaScript for 2019

#29

I might get heat for this but personally I find the JavaScript ecosystem to be a mess. There are so many changes to the language that are done aggressively which I think are done without much thought. For example, the promises API, now we also have async/await. The module system, with require(s), then import/export, and there's browser JS and system JS (node), and npm and now yarn, then your build system, with webpac…

Ryan Dahl seemed to imply that promises were a necessary pre-requisite for async/await. https://medium.com/@imior/10-things-i-regret-about-node-js-r...

I don't have the actual transcript so summarizing based off of someone else's comments:

* I added promises to Node in June 2009 but foolishly removed them in February 2010. * Promises are the necessary abstraction for async/await. * It's possible unified usage of promises in Node would have sped the delivery of the eventual standardization and async/await. * Today Node's many async APIs are aging badly due to this.

Re: What's New in JavaScript for 2019

#30
post #11
post #4

#this_is_not_a_comment = 6;

Yeah... it's ugly as heck but they're clearly trying to avoid new keywords. I hope the TypeScript folks can convince ECMA to adopt normal keywords like they use: https://www.typescriptlang.org/docs/handbook/classes.html

It's not just about keywords, it's about shadowing mostly [1].

For example, what does `this.foo` access in an object? the private property `foo`? the public property `foo`? What about if I'm using your object and put a new property `foo` on it after it's created, then what happens?

None of the answers to those questions are really good. If the private shadows the public, then how do you access the public? If it's the other way around, then external users can break your private fields by adding a public of the same name, which kind of defeats the purpose...

TypeScript can get away with it because it's not really enforced by the runtime, only the typechecker, so their `private` isn't really private outside of TypeScript.

[1] https://github.com/tc39/proposal-class-fields/blob/master/PR...

Post reply on HN