filmov
tv
JavaScript Short Tricks - Using generators to create sequential IDs
Показать описание
With generators being introduced in ES6, generating infinite, non-repeatable sequences has never been easier!
If you don’t know what generators are, they are functions that employ lazy evaluation by making use of the yield keyword to process and return data, on-demand.
It may look like generator functions will burn CPU cycles in an infinite loop, however, generators describe a state machine, allowing transitions to forward states to occur through provided code (through subsequent yields). These transitions occur on-demand whenever the next method is called, hence the term lazy evaluation!
With this trick, you no longer have to rely on global / class-scoped variables to remember the state!
#Coding #shorts #Webdeveloper #JavaScript #Tutorial
#Code #Github #Repo
If you don’t know what generators are, they are functions that employ lazy evaluation by making use of the yield keyword to process and return data, on-demand.
It may look like generator functions will burn CPU cycles in an infinite loop, however, generators describe a state machine, allowing transitions to forward states to occur through provided code (through subsequent yields). These transitions occur on-demand whenever the next method is called, hence the term lazy evaluation!
With this trick, you no longer have to rely on global / class-scoped variables to remember the state!
#Coding #shorts #Webdeveloper #JavaScript #Tutorial
#Code #Github #Repo