Live data from Hacker News

Overview of JavaScript ES6 features

adrianmejia.com

21–30 of 250 posts

Re: Overview of JavaScript ES6 features

#22
post #7

On the web browser side, I don't recommend using ES6 yet, without any kind of fallback. Internet Explorer 11 is still used, as are devices on older iOS versions. (without counting people using the default browser on pre-Lollipop Android)

Also - for anyone writing code where performance matters, the question isn't when browsers support the syntax, it's when each JS engine's optimizations support it.

E.g.: until some months ago just putting "let foo" into a function would cause V8 to bailout (meaning the whole function gets executed slowly, even if the actual let statement gets removed as dead code).

Unfortunately I've never found any good references on the optimizability of ES5+ features, so I've been avoiding them so far.

Re: Overview of JavaScript ES6 features

#24
post #2

Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed

The only language I've found / used so far that has these (expected) mechanics is Swift, which, when using a `let` for e.g. a list, will make the list itself immutable (in addition to the reference). It's really something that is confusing in every language that has some form of 'final', be it Java (which added immutable list implementations or wrappers to their existing collections), C++, JS, or what-have-you.

> The only language I've found / used so far that has these (expected) mechanics is Swift

Rust has similar semantics: https://is.gd/hsRjPh versus https://is.gd/ROgzXl

IIRC you can also declare const objects in C++, but constness is more complex and overridden there.

Re: Overview of JavaScript ES6 features

#25

Earlier quoted context omitted.

Common misconception, const only disallows reassignment. For instance, const number = 1337; number = 10; // fails But objects/arrays are not immutable in js, so you can do this: const person = { name: 'Dude' }; person.name = 'Dudette'; Which is perfectly valid. If you want full immutability, i recommend you check out https://facebook.github.io/immutable-js/ , been running it in production, a real pleasure to work wit…

FWIW Immutable.js is not deeply immutable. Seamless-immutable however is.

> Seamless-immutable however is.

Only in development mode, by freezing the objects.

Re: Overview of JavaScript ES6 features

#26
post #3
post #2

Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed

The const keyword makes the object reference constant. It doesn't make the object's value constant. You can change the contents of 'info' (info.push(5) is fine). You just can't change which object the variable points to. (info = [] will throw). If you know C/C++, the code 'const info = []' makes 'info' a constant pointer to a list not a pointer to a constant list . If you want to stop a variable from being changed, u…

This was what I came to comment on; when introducing ES6 features, this always trips people up. Thanks for "constant pointer to a list, not pointer to a constant list", I will use that next time I explain this.

This also means that objects defined with const can be mutated:

const x = { y: 2 }; x.y = 3;

Doesn't error. However with types that are immutable, like numbers and strings, const really is a constant: const HELLO = "hi" will never change.

Re: Overview of JavaScript ES6 features

#27
post #3
post #2

Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed

The const keyword makes the object reference constant. It doesn't make the object's value constant. You can change the contents of 'info' (info.push(5) is fine). You just can't change which object the variable points to. (info = [] will throw). If you know C/C++, the code 'const info = []' makes 'info' a constant pointer to a list not a pointer to a constant list . If you want to stop a variable from being changed, u…

[deleted]

Re: Overview of JavaScript ES6 features

#28
post #19

var's function scope is a feature! You don't have to place variable declarations in the header! (they are hoisted) Placing the var declarations where they are used makes the code easier to understand. The point of constructor functions is not having to write new . So classes does nothing besides syntactic sugars over the prototype system, witch actually makes it more complicated and the code harder to maintain. Async…

How is having var be function scoped instead of block scoped a useful feature?

Re: Overview of JavaScript ES6 features

#30
post #22
post #7

On the web browser side, I don't recommend using ES6 yet, without any kind of fallback. Internet Explorer 11 is still used, as are devices on older iOS versions. (without counting people using the default browser on pre-Lollipop Android)

Also - for anyone writing code where performance matters, the question isn't when browsers support the syntax, it's when each JS engine's optimizations support it. E.g.: until some months ago just putting "let foo" into a function would cause V8 to bailout (meaning the whole function gets executed slowly, even if the actual let statement gets removed as dead code). Unfortunately I've never found any good references o…

This is a real concern, but it definitely carries the usual caveats about premature optimization and needing to measure regularly to confirm that it is a real concern and that the performance landscape hasn't shifted since the last time you measured it.

The best suite I've seen is https://kpdecker.github.io/six-speed/ which measures node and the various modern browsers which Sauce Labs supports and appears to be run semi-regularly.

Post reply on HN