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
578
votes
11 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
  • 16,477
  • 6
  • 47
  • 78
434
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…
423
votes
26 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
  • 11,694
  • 20
  • 47
  • 76
382
votes
7 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,367
  • 2
  • 15
  • 15
197
votes
22 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.
  • 45,606
  • 92
  • 271
  • 433
196
votes
8 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
  • 11,433
  • 12
  • 57
  • 80
161
votes
11 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…
141
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
  • 52,180
  • 78
  • 198
  • 296
137
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
  • 10,195
  • 10
  • 36
  • 62
101
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
  • 11,694
  • 20
  • 47
  • 76
99
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,639
  • 3
  • 28
  • 39
70
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
  • 2,545
  • 5
  • 21
  • 27
48
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
  • 42,853
  • 9
  • 92
  • 91
45
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
  • 7,341
  • 7
  • 28
  • 45
44
votes
1 answer

Is "use strict" necessary in ECMAScript 6?

I'm wondering when ECMAScript 6 comes, do we still need to put "use strict" in js codes?
nightire
  • 1,350
  • 2
  • 11
  • 21
1
2 3
15 16