Is it possible to reset an ECMAScript 6 generator to its initial state?

If your intention is to some other scope, iterate over it, do some other stuff, then be able to iterate over it again later on in that same scope. Then the only thing you shouldn’t try doing is passing the iterator, instead pass the generator: var generator = function*() { yield 1; yield 2; yield … Read more

Function parameter definitions in ES6

What I don’t understand is how this relates to destructuring. Within removeBreakpoint, you can use url, line, and column directly. The destructuring happens when removeBreakpoint is called with an options object; that object’s matching properties are destructured into individual arguments. Is the idea that you permit the ability to pass an object into this function … Read more

JavaScript ES6: Test for arrow function, built-in function, regular function?

Believe it or not… Testing for presence of “=>” in string representation of a function is likely the most reliable way (but not 100%). Obviously we can’t test against either of 2 conditions you mentioned — lack of prototype property and lack of [[Construct]] as that might give false positives with either host objects or … Read more

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’)