Is there a mechanism to loop x times in ES6 (ECMAScript 6) without mutable variables?

Using the ES2015 Spread operator: […Array(n)].map() const res = […Array(10)].map((_, i) => { return i * 10; }); // as a one liner const res = […Array(10)].map((_, i) => i * 10); Or if you don’t need the result: […Array(10)].forEach((_, i) => { console.log(i); }); // as a one liner […Array(10)].forEach((_, i) => console.log(i)); Or … Read more

JavaScript double colon (bind operator)

No. The bind operator (spec proposal) comes in two flavours: Method extraction ::obj.method ≡ obj.method.bind(obj) “virtual method” calls obj::function ≡ function.bind(obj) obj::function(…) ≡ function.call(obj, …) Neither of them feature partial application. For what you want, you should use an arrow function: (…args) => this.handleStuff(‘stuff’, …args) ≡ this.handleStuff.bind(this, ‘stuff’)

What is the motivation for bringing Symbols to ES6?

The original motivation for introducing symbols to Javascript was to enable private properties. Unfortunately, they ended up being severely downgraded. They are no longer private, since you can find them via reflection, for example, using Object.getOwnPropertySymbols or proxies. They are now known as unique symbols and their only intended use is to avoid name clashes … Read more

When should I use arrow functions in ECMAScript 6?

A while ago our team migrated all its code (a mid-sized AngularJS app) to JavaScript compiled using Traceur Babel. I’m now using the following rule of thumb for functions in ES6 and beyond: Use function in the global scope and for Object.prototype properties. Use class for object constructors. Use => everywhere else. Why use arrow … Read more

One-liner to take some properties from object in ES 6

Here’s something slimmer, although it doesn’t avoid repeating the list of fields. It uses “parameter destructuring” to avoid the need for the v parameter. ({id, title}) => ({id, title}) (See a runnable example in this other answer). @EthanBrown’s solution is more general. Here is a more idiomatic version of it which uses Object.assign, and computed … Read more