Questions tagged [ecmascript-harmony]

ECMAScript Harmony is the code name for proposals aiming to extend the current ECMA-262 specification.

ECMAScript Harmony is the code name for proposals aiming to extend the current ECMA-262 specification and to form the new . It names the agreed design trajectory of post-ES5 editions. It will include syntactic extensions, but the changes will be more modest than ECMAScript 4 in both semantic and syntactic innovation.

Packages, namespaces, and early binding from ECMAScript 4 are no longer included for planned releases, and don't live under the roof of Harmony.

References

  1. ECMAScript - Wikipedia
  2. ECMAScriptHarmony - ECMAScript.org
239 questions
820
votes
10 answers

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,…
c69
  • 19,951
  • 7
  • 52
  • 82
648
votes
25 answers

How can I clone a JavaScript object except for one key?

I have a flat JS object: {a: 1, b: 2, c: 3, ..., z:26} I want to clone the object except for one element: {a: 1, c: 3, ..., z:26} What's the easiest way to do this (preferring to use es6/7 if possible)?
fox
  • 15,428
  • 20
  • 55
  • 85
496
votes
9 answers

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…
427
votes
8 answers

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…
Yanis
  • 4,847
  • 2
  • 17
  • 17
271
votes
11 answers

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 […
czerny
  • 15,090
  • 14
  • 68
  • 96
251
votes
24 answers

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…
at.
  • 50,922
  • 104
  • 292
  • 461
182
votes
3 answers

functional way to iterate over range (ES6/7)

What is the best way to do the below in more functional way (with ES6/ES7) let cols = []; for (let i =0; i <= 7; i++) { cols.push(i * i); } return cols; I tried like, return [ ...7 ].map(i => { return i * i; }); but that translated to…
bsr
  • 57,282
  • 86
  • 216
  • 316
177
votes
13 answers

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

How one can write a function, which takes only few attributes in most-compact way in ES6? I've came up with solution using destructuring + simplified object literal, but I don't like that list of fields is repeated in the code. Is there an even…
146
votes
6 answers

Methods in ES6 objects: using arrow functions

In ES6, both of these are legal: var chopper = { owner: 'Zed', getOwner: function() { return this.owner; } }; and, as shorthand: var chopper = { owner: 'Zed', getOwner() { return this.owner; } } Is it possible to use the new arrow…
fox
  • 15,428
  • 20
  • 55
  • 85
140
votes
1 answer

JavaScript double colon (bind operator)

As you know, there is a proposal for a shortcut for .bind() function, so you can write: ::this.handleStuff and it will work like that in es5: this.handleStuff.bind(this) My question is: will it be possible to pass arguments this way? I mean a way…
Victor Marchuk
  • 13,045
  • 12
  • 43
  • 67
112
votes
7 answers

What's the difference between ES6 Map and WeakMap?

Looking this and this MDN pages it seems like the only difference between Maps and WeakMaps is a missing "size" property for WeakMaps. But is this true? What's the difference between them?
Dmitrii Sorin
  • 3,855
  • 4
  • 31
  • 40
82
votes
7 answers

How to make an iterator out of an ES6 class

How would I make an iterator out of an ES6 class in the same manner as JS1.7 SomeClass.prototype.__iterator__ = function() {...} syntax? [EDIT 16:00] The following works: class SomeClass { constructor() { } *[Symbol.iterator]() { …
user5321531
  • 3,095
  • 5
  • 23
  • 28
56
votes
2 answers

What's the purpose of an asterisk (*) in ES6 generator functions

Can someone explain to me: why are generator functions in ES6 marked by asterisk symbol? For example, instead of: function *someGenerator() { yield 1; yield 2; yield 3; } we could write: function someGenerator() { yield 1; …
alexpods
  • 47,475
  • 10
  • 100
  • 94
52
votes
3 answers

When should I use let and var?

EDIT: Please read the question! I already know the difference. This is not a duplicate. Obviously, right now I should always be using the var key word as let isn't supported in everything. When the let keyword has better support (say, I'm writing a…
callumacrae
  • 8,185
  • 8
  • 32
  • 49
48
votes
3 answers

Immediate function using JavaScript ES6 arrow functions

Does anyone know how to write an immediate function using ES6 arrow syntax? Here's the ES3/5 way of doing it: (function () { //... }()); I've tried the following but get an unexpected token error on the last line. (() => { //... }()); You can…
d13
  • 9,817
  • 12
  • 36
  • 44
1
2 3
15 16