3 ms·
The article is not very good, with both factual mistakes and missing important sub-properties > 2. Array helper functions `map`, `filter`, `reduce`, `some` an
by masklinn 9y ago
The article is not very good, with both factual mistakes and missing important sub-properties
> 2. Array helper functions
`map`, `filter`, `reduce`, `some` and `every` were actually added in ES5.1. Only `find` and the unlisted `findIndex` come from ES6.
Meanwhile Array.from which was added in ES6 goes unlisted.
> 3. Arrow functions
While the reduction in definition boilerplate is great, missing is the very important (and convenient!) fact that arrow functions resolve `this` lexically (as a normal variable rather than a special case).
> 4. Classes
Would have benefited from mentioning the most convenient feature of classes by far: the `super` proxy to calling a method of the superclass on `this` (most useful with constructors): the ES5
<Superclass>.prototype.aMethod.call(this)
becomes:
super.aMethod()
which also helps a lot when moving methods around.
> 6. Template strings
Missing: you can "tag" template strings to invoke user-defined functions on the contents and do intermediate processing and interpolation yourself e.g.
sql`foo ${bar}`
will invoke `sql(['foo ', ''], <value of bar>)`.
> 7. Default function arguments
Missing note: unlike e.g. Python, default arguments are dynamic and sequential (similar to let<star>[0]) so you can define a `function foo(a, b=a)`.
> 8. Rest and spread operators
Actually the opposite for once, mentions that rest and spread operators can be used with object content, sadly that's currently a stage3 proposal, definitely not part of ES6.
> 9. Destructing
Missing notes:
* the destructuring is recursive (you're not limited to a single level)
* you don't have to "[assign values] to variables of the same name as properties" when destructuring objects:
let {name: a} = a_call();
will bind the value of the property "name" to the "a" local variable.
* you can provide default values to the destructuring pattern e.g.
let [a, b=3] = [1]
this can be combined with renaming for object destructuring
[0] http://docs.racket-lang.org/reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%2A%29%29 http://docs.racket-lang.org/reference/let.html#%28form._%28%... can't use an actual star there because HN comment formatting remains a complete trash fire and thus decides to emphasize half my comment and swallow the mark of the first list item. And still does not print let∗.
- cbaleanu 9y agoBad article, the author should have indeed put some more time into understanding what he is writing about. var firstTeenager = people.find(teenager) Stuff like this, when you write about ES6 features but use var makes my eyes hurt :(
- baron816 9y agoI agree that the article needs some work, but there really is nothing wrong with still using var. I'm in the Kyle Simpson camp and just use var for everything except if I'm actually creating a constant or block scoping comes into play or I need to prevent the hoisting of a variable. That way, it's clear what I'm doing and what my intentions are.
- masklinn 9y ago> That way, it's clear what I'm doing and what my intentions are. It's the exact opposite since you're defaulting to the most permissive binding style. Defaulting to `const` would actually make it clear what your intent is: you use `let` if you need mutable bindings and you use `var` if you need hoisting. If you default to `var` your intent is apparently to make use of mutable bindings and hoisting everywhere, at which point I can only expect that you put your variable declarations at the bottom of your function blocks after the `return` statement.
- baron816 9y agoDefaulting to const does nothing. If you or someone else decides later that it should be reassignable, then they'll change it and not think about it. If const is rare in your code, people will be aware of what const means in that context. If you're putting your variable declarations after your return statement, then you probably have other problems. I also don't know why you would ever expect someone to do that.
- masklinn 9y ago> Defaulting to const does nothing. If you or someone else decides later that it should be reassignable, then they'll change it and not think about it. Which they'll do regardless. `const` is an indication that the binding is not updated in the rest of the scope and thus that said scope can be perused without needing to consider an update to the binding itself. It is a guarantee of SSA, nothing more and nothing less. > If const is rare in your code, people will be aware of what const means in that context. The same as above which you apparently assert is "nothing"? > If you're putting your variable declarations after your return statement Why would I do that? I'm not adamantly using `var` when I have no reason to.
- agumonkey 9y agoI forgot the design of template strings, very nice. I think this should be adopted in most other languages.
- masklinn 9y agoThat is one thing which miffed me a bit about Python 3.6's f-strings. Whether their addition is useful or not may be up for debate but the inability to process them in userland seems one hell of a missed opportunity.