Hemanth.HM

A Computer Polyglot, CLI + WEB ♥'r.

Immediately-invoked Generator Function Expression (IIGFE)

| Comments

You would have heard of IIFEs, here is a intresting pattern I derived when playing with ES6 generators, call it Immediately-invoked generator function expression: IIGFE

1
2
3
4
5
6
7
pow = (function *() {
  return Math.pow((yield "x"), (yield "y"));
}());

pow.next(); // Object { value: "x", done: false }
pow.next(2); //Object { value: "y", done: false }
pow.next(3); //Object { value: 8, done: true }

Update 0:

Found a similar dicussion here

Comments