Live data from Hacker News

New Features in ES2019

javascript.christmas

91–100 of 123 posts

Re: New Features in ES2019

#91
These features are good (except I think Function.prototype.toString is a mistake).

(An alternative to String.prototype.trimStart would be to use String.prototype.replace, although trimStart would probably be more efficient.) Still some things missing includes: a goto command, ability to disable automatic semicolon insertion, macros, enhanced regular expressions, and a built-in regular expression quotation function (it is easily enough to implement in JavaScript, but it seem to me the kind of thing that should be built-in).

Re: New Features in ES2019

#92

Earlier quoted context omitted.

There's plenty of good reasons one doesn't exist. JSON is not JS-specific. It is a standard interchange format used by thousands of languages, many of which have very different date implementations. If you did have a JSON date, how would you decide what it was? Would it be a timestamp, or a civil date-time? Would it have timezones? Offsets? Locations? Would there be a database along with it required to understand it…

Why have a JSON number? Why not "just stick with" decimal strings?

I see your point, but numbers are easier to standardize than dates, so there is some logic to drawing the line there. It has to be drawn somewhere.

Re: New Features in ES2019

#93
I've wished for a stable sort. But there doesn't seem to be any reliable way to determine whether the current implementation is stable or not. For most language features, you can do detection to find out whether you can use it or not. This one seems to be different.

Re: New Features in ES2019

#94
post #69

> Optional catch binding Eh... that's great and all, but why not go the whole way and allow me to just use `try { }` without a catch-block? I'm sure that was part of a conversation somewhere, and I wonder why they chose not to go that far.

If it doesn't make any difference if the code inside the try block is executed or not, why even have the code in the first place? What is the use case for a try without a catch?

Opportunistically loading from a cache

Re: New Features in ES2019

#96
Good stuff! Normally I cringe to see new language features, but these are pretty good (Java after lambdas, even arguably after generics, is pretty crufty, IMHO)

One thing I'd to request is that `Object.fromEntries()` simply skip undefined entries, rather than do...strange things. I wrote an `mapObject` function that looks like `(a,fn) => Object.fromEntries(Object.entries(a).map(fn))` and occasionally the fn needs to skip an entry and the easiest way to do this is just return `undefined`.

Re: New Features in ES2019

#97
One thing I would fix about JavaScript is that currently "return" followed by a newline returns undefined. I would say that only return followed by ';' should return undefined. Else it should return the value of the expression following "return", whether on the same line or not, until the next ";".

Not sure how how much backwards compatibility this would break, but at some point we must allow for newer better less error-prone versions of the language to co-exist in different modules. That is not difficult at all. Consider the case of "use strict"; which does just such a thing. We could have "use strict 2020" etc.

Re: New Features in ES2019

#98
post #5

Earlier quoted context omitted.

Another sort() quirk that catches people out is not realising it uses string comparison by default [1,2,10].sort() = [1,10,2]

> is not realising it uses string comparison by default Hell, really?? That's gross. As for the parent's comment about a dev "not realising array.sort() was unstable", the dev should know his tools. I can't see anyway why a stable sort is better, I've never sorted on x then sorted on x, you just sort on x & y.

Hell, really?? That's gross.

It's just using the == operator, no? Which, yes, is really gross.

Re: New Features in ES2019

#99

Not ES directly, but you know what I need on an almost daily basis? A JSON date type. It’s obnoxious to have to pass a string back and forth and parse it on either end between server and browser.

You can use an unix epoch (seconds or milliseconds from 1/1/1970) to make parsing very fast. This is naturally supported by Javascripts new Date() too.

its ok for instants but not dates: receiving side may truncate the instant to a date in a different timezone env than the sender (easily done and will NOT be UTC by default in many envs) -and then you may have an off-by-one on the day.

Re: New Features in ES2019

#100

Earlier quoted context omitted.

I hear this a lot, but everything can be handled with a single tool: Webpack. Even a TS project can compile with Webpack and all of its assets, minification and compression needs can be handled in the same file. While you’re at it you can set up a development server with source mapping. Just take an afternoon to learn Webpack and be done with complaining about setup overhead. I set up a multi-stage build for TS Proje…

> take an afternoon to learn we pack If only it was that easy. The weeks I’ve spent hunting down webpack specific bugs because the plugins don’t always quite work with typescript transformations and source maps...

If you have spent multiple weeks on a Webpack bug then you are not trying to fix it. You could have asked Stack Overflow over and over again in a matter of weeks.

There are many options for source maps due to their performance overhead and the docs describe then in detail and provide a guide for when to use each one.

Post reply on HN