DEV Community

Cover image for Typewriter effect with vanilla async generators functions
Pasquale Mangialavori
Pasquale Mangialavori

Posted on

Typewriter effect with vanilla async generators functions

Easy peasy lemon squeezy!


Edit speller

Top comments (2)

Collapse
 
lionelrowe profile image
lionel-rowe

Nice demo! Note that strings are already iterable, so you can simplify spell like this:

async function* spell({ sentence, slowness = 75 }) {
  for (const char of sentence) {
    await delay(slowness);
    yield char;
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
eatsjobs profile image
Pasquale Mangialavori

True! It actually implements Symbol.iterator. thanks for pointing it out. :)