---
title: "Immediately-Invoked Generator Function Expression (IIGFE)"
description: "A new pattern for immediately invoked generator functions in ES6. Practical notes and code examples on Immediately-Invoked."
url: "https://h3manth.com/scribe/immediately-invoked-generator-function-expression-iigfe/"
canonical_url: "https://h3manth.com/scribe/immediately-invoked-generator-function-expression-iigfe/"
markdown_url: "https://h3manth.com/scribe/blog/immediately-invoked-generator-function-expression-iigfe.md"
publishDate: "2014-07-08T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["javascript","es6","generators"]
word_count: 83
reading_time_minutes: 1
x_markdown_tokens: 230
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Immediately-Invoked Generator Function Expression (IIGFE)

> A new pattern for immediately invoked generator functions in ES6. Practical notes and code examples on Immediately-Invoked.

You've heard of [IIFEs](https://en.wikipedia.org/wiki/IIFE), here's an interesting pattern I derived when playing with ES6 generators - the Immediately-Invoked Generator Function Expression (IIGFE):

```javascript
pow = (function *() {
  return Math.pow((yield "x"), (yield "y"));
}());

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

The generator is immediately invoked and returns an iterator that you can interact with step by step, passing in values at each `yield` point.
