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

The typical way to loop x times in JavaScript is: for (var i = 0; i < x; i++) doStuff(i); But I don’t want to use the ++ operator or have any mutable variables at all. So is there a way, in ES6, to loop x times another way? I love Ruby’s mechanism: x.times do … Read more

How to customize object equality for JavaScript Set

New ES 6 (Harmony) introduces new Set object. Identity algorithm used by Set is similar to === operator and so not much suitable for comparing objects: var set = new Set(); set.add({a:1}); set.add({a:1}); console.log([…set.values()]); // Array [ Object, Object ] How to customize equality for Set objects in order to do deep object comparison? Is … Read more

What is the motivation for bringing Symbols to ES6?

UPDATE: Recently a brilliant article from Mozilla came up. Read it if you’re curious. As you may know they are planning to include new Symbol primitive type in ECMAScript 6 (not to mention some other crazy stuff). I always thought that the :symbol notion in Ruby is needless; we could easily use plain strings instead, … Read more

When should I use arrow functions in ECMAScript 6?

With () => {} and function () {} we are getting two very similar ways to write functions in ES6. In other languages lambda functions often distinguish themselves by being anonymous, but in ECMAScript any function can be anonymous. Each of the two types have unique usage domains (namely when this needs to either be … Read more

How to convert Set to Array?

Set seems like a nice way to create Arrays with guaranteed unique elements, but it does not expose any good way to get properties, except for generator [Set].values, which is called in an awkward way of mySet.values.next(). This would have been ok, if you could call map and similar functions on Sets. But you cannot … Read more