One thing that I am a bit afraid about though is that the language might become more complex and complicated over time because of backward compatibility (C++-like?). I saw that they will be introducing a new function "replaceAll(...)" to avoid the weird semantics of "replace(...)" (stopping after first occurrence unless a 'global' RegExp is passed as argument). And that's great, but that's a new function, and maybe 'replace(...)' should have had this behavior from the start. I hope to be wrong on this one!
New Features in ES2019
11–20 of 123 posts
Re: New Features in ES2019
#12Re: New Features in ES2019
#13I wonder what kind of shenanigans you could do with Function.toString(). It'd be even better if they had Function.toAST().
Re: New Features in ES2019
#14I wonder what kind of shenanigans you could do with Function.toString(). It'd be even better if they had Function.toAST().
Re: New Features in ES2019
#15Earlier 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]
It’s the curse of the optional arguments. Same thing with parsing numbers where the second argument magically specifies the base. If the comparison function argument was mandatory in sort() this wouldn’t be a problem.
Stupid defaults is not "the curse of optional arguments", it's the curse of stupid defaults.
Most languages have defaults for these two operations yet have proper defaults rather than stupid ones. Python's list.sort() and int() certainly do, so do Java's Collections.sort() and Integer.parseInt().
Uniquely awful defaults is a historical (and defining) feature of javascript, not of having default values, or optional arguments.
Re: New Features in ES2019
#16Re: New Features in ES2019
#17Not 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.
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 correctly?
Just stick with ISO8601 strings.
Re: New Features in ES2019
#18I wonder what kind of shenanigans you could do with Function.toString(). It'd be even better if they had Function.toAST().
Re: New Features in ES2019
#19Earlier quoted context omitted.
It’s the curse of the optional arguments. Same thing with parsing numbers where the second argument magically specifies the base. If the comparison function argument was mandatory in sort() this wouldn’t be a problem.
> It’s the curse of the optional arguments. Same thing with parsing numbers where the second argument magically specifies the base. Stupid defaults is not "the curse of optional arguments", it's the curse of stupid defaults. Most languages have defaults for these two operations yet have proper defaults rather than stupid ones. Python's list.sort() and int() certainly do, so do Java's Collections.sort() and Integer.pa…
[1,2,10].map(parseInt)
It’s several things that on their own aren’t mad which taken together produces a crazy result. 10 as the default for an optional second argument of parseInt is fine. But map should only use a single argument closure by default. So map(parseInt) must be equivalent to map(x -> parseInt(x)).
Re: New Features in ES2019
#20Not 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.