Why does the Promise constructor require a function that calls ‘resolve’ when complete, but ‘then’ does not – it returns a value instead?

Bergi’s answer is excellent, and has been very helpful to me. This answer is complementary to his. In order to visualize the relationship between the Promise() constructor and the then() method, I created this diagram. I hope it helps somebody… maybe even me, a few months months from now. The main idea here is that … Read more

How does Observables (Rx.js) compare to ES2015 generators?

Observables push changes, and hence the observable, not the function reacting to it, is in control. Generators on the other hand require you to pull values out of them. So the function that will react to the new value determines when it is ready for a new value. I had trouble with backpressure using observables, … Read more

What does the “…” (triple dot) notation in arrays mean? [duplicate]

The …(spread operator) works by returning each value from index 0 to index length-1: As example: […’18’] // returns [‘1’, ‘8’] which would be the same as: [’18′[0], ’18′[1]] Now, to get an array from 1 to 18, you can do this: […Array(19).keys()].slice(1) Or this with map: […Array(18)].map(_=>i++,i=1) Hope it helps.

Serializing an ES6 class object as JSON

As with any other object you want to stringify in JS, you can use JSON.stringify: JSON.stringify(yourObject); class MyClass { constructor() { this.foo = 3 } } var myClass = new MyClass() console.log(JSON.stringify(myClass)); Also worth noting is that you can customize how stringify serializes your object by giving it a toJSON method. The value used to … Read more