Reason why generators do not have references to themselves?

Brendan Eich brendan at mozilla.com
Thu Jan 23 15:43:49 PST 2014


Andrea Giammarchi wrote:
> arguments.callee.caller would have done that </trolling> 
> </but-actually-not-so-much>

No, Bradley wants the generator-iterator (what ES6 draft calls a 
Generator), not the generator function (GeneratorFunction). Any .callee 
would have to be a function, so a GeneratorFunction.

But the gist'ed example won't work:

   function*  doLogin_()  {
     try  {
       /* START ASYNC TRANSPILE */
       login(req).then(function  (session)  {
         gen.next(session);


You can't next an active generator.

Instead, the trick is to avoid promises inside the generator function. 
Put them "on the outside" (and "backstage") as task.js does. 
http://taskjs.org/.

/be


More information about the es-discuss mailing list