Overview of JavaScript ES6 features
21–30 of 250 posts
Re: Overview of JavaScript ES6 features
#22On 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)
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
#23Re: Overview of JavaScript ES6 features
#24Using 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.
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
#25Earlier 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.
Only in development mode, by freezing the objects.
Re: Overview of JavaScript ES6 features
#26Using 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 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
#27Using 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…
Re: Overview of JavaScript ES6 features
#28var'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…
Re: Overview of JavaScript ES6 features
#29Re: Overview of JavaScript ES6 features
#30On 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…
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.