#JavaScript

Publié le: 14 novembre 2023
sur la chaîne: Tiny Frontend - 1 Minute Video Sharing
72
2

🎨✨ Read More ↓ ↓ ↓

A generator function allows you to control the execution and retrieve results in phases.
It is defined using the function * syntax and contains one or more yield expressions.

When a generator function is called, it returns a special generator iterator.
This iterator can be used to control the execution of the generator function.

Now, let's see how is the generator used in the real world.
We're going to use a pagination fetcher generator to implement the infinite loading feature.
When the page scrolls near the end, the JavaScript will fetch the content of next page automatically.

01. Define the fetcher generator.
The generator enters an infinite loop using while.
This loop is intentional because the generator will be paused after each API call.

02. Call the Generator Functions
We set a listener to trigger the iterator for the api fetching without any parameter.

#TinyFrontend #WebDevelopment #frontend #frontenddeveloper #frontenddev #frontenddevelopment #frontendwebdeveloper #frontendengineer #frontendengineering #frontendmasters #generator #javascript #pagination


Sur cette page du site, vous pouvez voir la vidéo en ligne #JavaScript durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Tiny Frontend - 1 Minute Video Sharing 14 novembre 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 72 fois et il a aimé 2 téléspectateurs. Bon visionnage!