JavaScript Generators Tutorial
HTML-код
- Опубликовано: 13 сен 2016
- Generators in JavaScript Explained
In this tutorial we will look iterators and generators.
- We understand iterators in JavaScript
- Look at a new property called symbol.iterators
- Look at practical use of iterators.
#javaScript #generators #interators
*My Udemy Courses
www.udemy.com/js-masterclass/
www.udemy.com/course/react-ho...
Follow me for technology updates
* / techsith
* / techsith
* / techsith1
* / 13677140
* / patelhemil
Help me translate this video.
* ruclips.net/user/timedtext_cs_...
Note: use translate.google.com/ to translate this video to your language. Let me know once you do that so i can give you credit. Thank you in advance. Наука
Thank you so much for your tutorials. Came for the memes, stayed for the dreams.
I can say one of the best videos on Java script ,key is ,you explain in simple terms not going by books .Please do more and help the community out there .My likes are for closures and promises :-)
Thanks for watching Karthik
Nice and clean. Great video, thank you
Thanks for the wonderful explanation.
as always, great video!
awesome content!!!!
Very well explained, thank you!
nice info
awesome videos man, thanks!!
keep up the good work :)
You explain this perfect! going to use it in Israel to explain my students and also giving your videos!!
Thank you for your great videos! I would like to see a course from you about design patterns like the observer, singleton patterns and generaly how to structure efficiently and DRY an application by real world examples in react or vanilla js! Greetings from Greece!
Really awesome
Great, thank you!
Here from Redux Saga tutorial. Your videos are short and help me revise the concept. Good work sir 👍
you are great teacher, thanks for making more familiar with your easy explanation :)
please put this video after iterators tutorial in advanced javascript tutorial;
also your channel is awesome, it covers a lot of things I was looking for after going from absolute basics to more advanced things - you explain them really straightforwardly
iterators and generators might be just what I was looking for - I've got
reocurring problem with iterate through arrays using for loop, and getting
expected value after every iteration (not just when value of "i" reaches
it's limit) - I have to write function for every case.
Very nice !👍
Dude thumbnail is sickkkkk!!!!!!!
this guy is awesome.
Beautiful
thanks, nicely explained
Thanks for tutorials
Where has this guy been all my life?
nice
great tuto
Hi, your videos are very useful.
I got corrected with the navigation menu issues.
Thanks for your reply. Can you post some video for google map placing in a website javascript code?
Thanks
@techsith: Awesome! thank you for the video.
thanks for watching :)
Hi TechSith....I just want to say...I love watching your tutorials...very nice explanation with real-time example... really it's helping us a lot....
Keep Learning and Thanks for watching!
Excellently explained... Just looking for... Thank you very much sir :)
You are most welcome. thanks for watching!
Thx
Great work. Thank you so much. :)
Akshay, thanks for watching!
excellent
Thanks for watching!
Thanks. I wanted to learn Iterators and Generators so I could use Mongorito which makes extensive use of yield statements in its API.
As an added bonus, I now know how to make my code cleaner with Generators.
Impressed and subscribed just after this one.
Thanks for subscribing!
@@Techsithtube you won't go out of list never ever ever ever ever... 😋
Could you also illustrate on passing an argument into the generator function via ".next(argument)"? I am very confused about this.
Cool. This is how I can pipe multiple REST api calls, say sequencially, when there is a data dependency under a generator and call it from my GUI. (Poor peoples redux middleware😭). 🙏
great explanation. just one thing: 10:55 there is no dependency between yields, it won't wait untill first is finished - it resume executing in case continuing calling of next()
Correct there is no dependency if you run 2 next() back to back both two request will be sent and won't wait for each others' responses
Sir, It means, request(url1) and request(url2) is working in a synchronous manner, blocking approach of execution? Please explain
Hi Sir,
For the last example you gave:
function *generator(){
yield request('url1');
yield request('url2');
}
This is an easier version for .then callback? Are there any differences between using .then and this method? Thank you for your video!!
Well it can be a good replacement however. combing both together would get you async await. I am sure you must have heard of it. Its combination of generators and promises that makes async code looks like sync code.
should I learn Angular2 or React?!! I'm so torn, help!
Pretty late here but surely React first. Lower learning curve + Getting better at vanilla Javascript + Massive job opportunities.
It's really a no-brainer.
You can learn Angular after that.
Thanks! very useful!
btw, why can I use "let iterator = i.Symbol.iterator()" and have to use let iterator = i[Symbol.iterator]()
it gives error "VM257:1 Uncaught TypeError: Cannot read property 'iterator' of undefined
at :1:24"
same question
It's been 2 weeks, but I hope it's still useful.
"i.Symbol.iterator()" will first try to find 'i.Symbol'. It's the same as saying 'i["Symbol"]'. This doesn't exist, so it gives you 'undefined'.
Then it tries to call 'iterator()' on that 'undefined' and fails.
You can see now how 'i["Symbol"]' uses a different key from 'i[Symbol.iterator]'; the first is a String object, the second is a Symbol object.
Dalendrion U R THE MAN ty
Дмитрий Сухарев No problem, man.
Hi, thanks for your tutorial, but I have one question. This generators practical example with promises... why should I use generators instead of .then in Promises. It works the same :).
Regards!
the idea is to make 2nd url request call after first call (promise) resolve. with generator you only need to call .next() after first call success / resolved. will help a lot if the generator is in separate file / class
I have a doubt in generator example using promise : For this specific example of generator with promise, it seems i can do the such dependent url calls using only promise so that 2nd url call will happen until first finishes and use 1st url data in 2nd, so why do we use generator here ? Please correct me if i am wrong. Thanks for such excellent tutorials !
Lets say if you want to cancel a promise , using generators you can do it.
Hello @techsith, could you provide an example of this case. I did not find anyone . this interest me very much :s
We can do same with promises using async await then what is the difference?
Async await is nothing but mix of promises and generators.
Where we can use this?
Love your thumb nails
gj
let iterator = i [ Symbol.iterator ]() ;
why wrapping Symbol.iterator within third brackets [ ] ?
becase by ecma definition iterators are accessed like thisArray.prototype[@@iterator]()
Why can't I just do this?
let iterator = i[Symbol.iterator]().next() //this just stays at array[0]
Instead of console.log(iterator.next()) everytime?
You could its perfectly file. However , every time you call next it has todo i[Symbol.iterator]() which is little bit expensive computation wise.
Why not use await instead of yield? I don't get why use this.
Generators was used before async/await. I think async/await uses generators under the hood.
if I call generator().next(); instead of iterator.next(); the value is always 1. Could you please make me understand?
Vishwa, generator() a new Iterator every time that is why generator().next() gives you 1 which is the first value.
@@Techsithtube thank you so much 🙏🏻
apri