Real life usage of generators functions in js

Discussão em 'Angular' iniciado por vikrant, Novembro 11, 2024.

  1. vikrant

    vikrant Guest

    const foo = function* () {
    yield 'a';
    yield 'b';
    yield 'c';
    };

    let str = '';
    for (const val of foo()) {
    str = str + val;
    }

    console.log(str);
    // Expected output: "abc"


    This is a example of js generators function. But where are we going to use this function in daily software development.

    Like Closure applications are private variables implementation, counter, rate limitter.

    Continue reading...

Compartilhe esta Página