News for hackers. Stuff that matters.
Re:ES6 Overview in Bullet Points by ponyous on Friday November 27, 2015 @01:49PM (#10638367)
Looking good and informative, but to be honest I am really interested in use cases. I think I understand how to use generators but I have no idea where I could use them in real-world scenarios. Same goes for WeakMaps, Proxies... Anyone care to give some examples?
Re:ES6 Overview in Bullet Points by chowes on Friday November 27, 2015 @02:13PM (#10638462)
Check out http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaS... and the follow up post. It's easy enough to start using generators alongside your existing async solution (callbacks or promises).

Proxies can be used for data-binding, similar to Object.observe.

I've also yet to find a case where I need WeakMaps instead of an Object or Map. All the benefits seem to be a bit too theoretical, but I likely haven't dug into it hard enough.

Re:ES6 Overview in Bullet Points by danielnaab on Friday November 27, 2015 @03:00PM (#10638637)
I've used a WeakMap for a kind of memoization.

Assume an immutable object may undergo an expensive transform that returns an object, which is then stored in a WeakMap keyed to the immutable. When there are no new references to that object, the garbage collector will clean it up, but otherwise the expensive transform may be avoided with a lookup on the WeakMap.

It provides a pretty nice way to decouple your caching from the rest of the codebase.

Re:ES6 Overview in Bullet Points by heifer2822 on Friday November 27, 2015 @01:59PM (#10638402)
checkout Koa to see a great use case of generators. By yielding to asychronous code (instead of callbacks) you can write JS that looks like it's synchronous.
Re:ES6 Overview in Bullet Points by NikolaeVarius on Friday November 27, 2015 @03:23PM (#10638714)
What is the advantage of using generators versus promises?
Re:ES6 Overview in Bullet Points by chowes on Friday November 27, 2015 @04:13PM (#10638872)
http://stackoverflow.com/a/28032438 gives a great overview to the pros and cons of both approaches.
Re:ES6 Overview in Bullet Points by callahad on Friday November 27, 2015 @03:51PM (#10638783)
In this case, Koa uses generators and promises together to emulate the behavior of async/await style concurrency. You can see how Babel 5.x transforms ES7 async/await into generators and promises at https://github.com/babel/babel/blob/v5.8.34/packages/babel/s...
Re:ES6 Overview in Bullet Points by _greim_ on Friday November 27, 2015 @09:24PM (#10639751)
Too many use cases to list, but generally a nice way to for...of anything, for example a recursive binary tree traversal:

    [Symbol.iterator]() {
      if (this.left) {
        yield* this.left[Symbol.iterator]();
      }
      yield this.value;
      if (this.right) {
        yield* this.rightSymbol.iterator]();
      }
    }
    ...
    for (const value of myTree) { ... }
Re:ES6 Overview in Bullet Points by slasaus on Friday November 27, 2015 @02:49PM (#10638598)
I'm currently using Proxy to transparently version data that is saved in an IndexedDB.