Earlier quoted context omitted.
Vi vs Emancs? Weak vs strong typing?? tabs vs spaces??? where did you get those?? The ONLY holy war in JS is the semi-colon one
That's what OP is saying: programming has plenty of holy wars that predate JavaScript.
Overview of JavaScript ES6 features
231–240 of 250 posts
Re: Overview of JavaScript ES6 features
#232Earlier quoted context omitted.
We use Babel to compile ES6/ES7/ES8 to ES5. https://babeljs.io
It's not what the article is about. The article is obviously talking about native ES6 features, otherwise it would advertise es7 features as well and advise to use transpilers.
I'd actually recommend avoiding the still-not-standardized features as you'll have less/no change when it lands in browsers.
Re: Overview of JavaScript ES6 features
#233Earlier quoted context omitted.
From the article-- let x = 'outer'; function test(inner) { if (inner) { let x = 'inner'; return x; } return x; // gets result from line 1 as expected } test(false); // outer test(true); // inner This makes it seem like let creates global variables. Why would you want to return a variable from outside the function? Doesn't that create massive overhead in terms of keeping track where variables are initially set? Easy t…
If you were to then reference 'x' from another block of code, say in another element in the case of web development, 'x' would not be a defined variable, whereas with 'var', it would be. This is mostly just a case of 'let' restricting a variable to the block it is in, and the child blocks. In your example, `let x = 'outer';` is sort of acting like a global variable, but the importance is that if another script were t…
I'll read more into uses of let over var. Function level scoping a la var feels like less mental overhead, but as I read more I'm sure my opinion will change.
Re: Overview of JavaScript ES6 features
#234Earlier quoted context omitted.
For anyone who wants to use ES6 in production, https://babeljs.io/ is amazing.
It's both amazing, and 600MB worth of dependencies. We use it for server-side code. It's high quality, and we only have a few issues with it, but I can't wait to be able to ditch is (pretty much when async/await lands in a stable node).
We get a lot of millage out of it even when our target platforms support all the language features we need. Your millage may vary.
Re: Overview of JavaScript ES6 features
#235"you can start using it right now" if you don't care about IE8, IE9, IE10, and many mobile browsers and are willing to ignore 20% of your customers. e.g: http://caniuse.com/#search=let const does not have block scope in those browsers either, but will work, adding to your debugging confusion. template literals and multiline string has no IE support at all (you need edge: https://developer.mozilla.org/en-US/docs/Web/J…
A transpiler just adds another layer of complexity that it's best to avoid as much as possible, in my opinion. It's not a perfect example, but if you've ever worked with CoffeeScript and run across a bug or unexpected side effect in the final rendered code . . . that should curb some of the transpiler enthusiasm.
Some of the ES6 features look handy enough, but I'd prefer waiting to see which ones shake out as actually useful over time, versus which are just momentary novelties.
Re: Overview of JavaScript ES6 features
#236Earlier quoted context omitted.
Arrow functions get auto-named in many browsers based on how they are used. This auto-naming is actually being somewhat standardized between browsers and means there is no difference between anonymous-style function () {} and arrow functions. Promises are more than just a wrapper around callbacks because they also standardize behavior between "stacks" of callbacks, by instead "chaining" them and creating a standard i…
Promises spreads like a virus so that all asynchronous functions eventually end up returning a Promise. They are hard to understand and it's easy to forget handling errors or return values. I think callbacks are much easier to understand and get right using named functions and closures. If you want to call everything in serial and wait between each step, why not make it synchronous instead of .then chaining ?
The "magic" that Promises bring to code is that they "just look serial" with .then() chains. That's part of the point of Promises and that's part of the infrastructure what powers the ability to write async/await code. Just because it looks nice and serial doesn't mean it is synchronous. (In High Functional speak, Promises are the Continuation monad, and the near isomorphism with synchronous code (especially async/await) is a wonderful product of standardizing the monad.)
Which is to say: tl;dr: Promises spreading like a virus is a feature, not a bug.
Re: Overview of JavaScript ES6 features
#237I'm surprised by the state of const/let nowadays. The well-known good practice: use const by default; use let when it's needed. At the release of ES6, it was the way to go. But everyday I notice libraries—and some really famous— that use let everywhere in their docs, or some really influent developers from Google or Facebook who share samples of code on Twitter using let when it's not needed [1]. I don't know why. Se…
How do you feel about `const` for variables that are not reassigned but are still mutated? const array = [1, 2, 3]; array.push(100); // unexpected? I prefer to use let for bindings to objects that get mutated, even if the variable is not re-bound.
Re: Overview of JavaScript ES6 features
#238Earlier quoted context omitted.
How does this work? I can't find any examples and I also don't really understand what mechanism makes your npm module work.
A tagged template literal is just a special ES6 syntax for calling a function with a specific set of arguments. You could pass a function which returns all of the arguments as an array to see what's passed in. Try the following in the console of a modern browser: function log(...args) { return args; } log `abc ${'blah'} fooo\n ${12+3} bar`; Or you could even shorten the above down to this: ((...args)=>args) `abc ${'b…
Re: Overview of JavaScript ES6 features
#239Earlier quoted context omitted.
How does this work? I can't find any examples and I also don't really understand what mechanism makes your npm module work.
A tagged template literal is just a special ES6 syntax for calling a function with a specific set of arguments. You could pass a function which returns all of the arguments as an array to see what's passed in. Try the following in the console of a modern browser: function log(...args) { return args; } log `abc ${'blah'} fooo\n ${12+3} bar`; Or you could even shorten the above down to this: ((...args)=>args) `abc ${'b…