> For the complete documentation index, see [llms.txt](https://strctr.gitbook.io/programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://strctr.gitbook.io/programming/01-languages/javascript/01-language/e-controls/e3-generators/02-generator-syntax.md).

# 02. Generator Syntax

Генераторы имеют особый синтаксис. Заключается он в добавлении звёздочки к определениям функций, за исключением стрелочных функций и объявлений геттеров и сеттеров. В результате получаются объявления функций и методов, функциональные выражения, и даже конструкторы.

```javascript
// Объявление генератора
function* BindingIdentifer() {}

// Ещё одно объявление не слишком анонимного генератора
export default function*() {}

// Анонимное выражение генератора
(function*() {});

// Определение методов
let object = {
  *methodName() {},
  *["computedName"]() {}
};

// Определение методов в объявлении класса
class C {
  *methodName() {}
  *["computedName"]() {}
}

// Определение статических методов в объявлении класса
class C {
  static *methodName() {}
  static *["computedName"]() {}
}

// Определение методов в выражении класса
let C = class {
  *methodName() {}
  *["computedName"]() {}
};

// Определение статических методов в выражении класса
let C = class {
  static *methodName() {}
  static *["computedName"]() {}
};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://strctr.gitbook.io/programming/01-languages/javascript/01-language/e-controls/e3-generators/02-generator-syntax.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
