DEV Community

loading...

Discussion on: Understanding Generators in ES6 Javascript

Collapse
k3rnel_err0r profile image
Antonio Quintero-Felizzola

Loved the article! I was wondering if we can use more combinations in the yield part . I don't know, maybe callbacks? Is it possible?

function* avengersGenerator() {
  yield "Hulk";
  yield greeting
  yield "Spiderman";
}

function greeting() {
  console.log("Hi, Tuan!")
}

I have not tested it yet 😓

Collapse
tuanphungcz profile image
Tuan Phung ⚡️ Author • Edited

yes, we can! You need to any function there ;)

function greeting() {
  console.log("Hi, Antonio!")
}

function* avengersGenerator() {
  yield "Hulk";
  yield greeting()
  yield "Spiderman";
}