Last active
November 13, 2018 06:07
-
-
Save ltciro/c5acf9c36860a63ef876088b34edab41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//se crea la función generadora con la anotación "function*" | |
const arr = function* arrGen(){ | |
yield 1 // yield detiene la función, devuelve 1 y cuándo se ejecute de nuevo next() | |
// continuá en la siguiente linea de código la #5 | |
yield 2 // yield detiene la función, devuelve 2 y cuándo se ejecute de nuevo next() | |
// continuá en la siguiente linea de código la #7 | |
yield 4 // yield detiene la función, devuelve 2 y cuándo se ejecute de nuevo next() | |
// devulve undefined y la propiedad done igual a true | |
} | |
const arrInstance = arr(); | |
console.log('Next in array_as_generator 1', arrInstance.next()) | |
// Next in array_as_generator 1 | |
// {value: 1, done: false} | |
console.log('Next in array_as_generator 2', arrInstance.next()) | |
//Next in array_as_generator 2 | |
//{value: 2, done: false} | |
console.log('Next in array_as_generator 4', arrInstance.next()) | |
//Next in array_as_generator 4 | |
//{value: 4, done: false} | |
console.log('Next in array_as_generator?', arrInstance.next()) | |
//Next in array_as_generator? | |
//{value: undefined, done: true} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment