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.
  • НаукаНаука

Комментарии • 77

  • @CoryTheSimmons
    @CoryTheSimmons 6 лет назад +13

    Thank you so much for your tutorials. Came for the memes, stayed for the dreams.

  • @karthiksurvepalli5695
    @karthiksurvepalli5695 3 года назад +2

    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 :-)

  • @sparxmike
    @sparxmike 5 лет назад +2

    Nice and clean. Great video, thank you

  • @Atif1702
    @Atif1702 6 лет назад +3

    Thanks for the wonderful explanation.

  • @goytayibarek
    @goytayibarek 2 года назад

    as always, great video!

  • @devanshvashishta
    @devanshvashishta 2 года назад

    awesome content!!!!

  • @Versiloff
    @Versiloff 4 года назад

    Very well explained, thank you!

  • @AnimeshSinghweb
    @AnimeshSinghweb 3 года назад

    nice info

  • @harshwardhanrathore8973
    @harshwardhanrathore8973 7 лет назад

    awesome videos man, thanks!!
    keep up the good work :)

  • @monkyes
    @monkyes 5 лет назад

    You explain this perfect! going to use it in Israel to explain my students and also giving your videos!!

  • @GoDGoRyGR
    @GoDGoRyGR 5 лет назад +2

    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!

  • @sagarkalokhe4793
    @sagarkalokhe4793 5 лет назад

    Really awesome

  • @thomasgauperaa4659
    @thomasgauperaa4659 6 лет назад

    Great, thank you!

  • @kitchen-e-kausar9105
    @kitchen-e-kausar9105 2 года назад

    Here from Redux Saga tutorial. Your videos are short and help me revise the concept. Good work sir 👍

  • @vandanasaini3520
    @vandanasaini3520 3 года назад

    you are great teacher, thanks for making more familiar with your easy explanation :)

  • @Poszlakowaneopinie
    @Poszlakowaneopinie 7 лет назад

    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.

  • @imranshaikh115
    @imranshaikh115 5 лет назад

    Very nice !👍

  • @relievestress557
    @relievestress557 3 года назад

    Dude thumbnail is sickkkkk!!!!!!!

  • @olorinorphique
    @olorinorphique 5 лет назад

    this guy is awesome.

  • @vinodbhatt3789
    @vinodbhatt3789 5 лет назад

    Beautiful

  • @harshulkansal6786
    @harshulkansal6786 3 года назад

    thanks, nicely explained

  • @pratikvanol482
    @pratikvanol482 4 года назад

    Thanks for tutorials

  • @Kidpunk98
    @Kidpunk98 2 года назад

    Where has this guy been all my life?

  • @EnimaIffets
    @EnimaIffets 7 лет назад

    nice

  • @limitless9483
    @limitless9483 4 года назад

    great tuto

  • @akalyamohan2023
    @akalyamohan2023 7 лет назад +1

    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?

  • @yashwanthsrini
    @yashwanthsrini Год назад

    Thanks

  • @ambicabassetty4482
    @ambicabassetty4482 7 лет назад +7

    @techsith: Awesome! thank you for the video.

  • @damit0071
    @damit0071 5 лет назад

    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....

    • @Techsithtube
      @Techsithtube  5 лет назад

      Keep Learning and Thanks for watching!

  • @sukantadhar8784
    @sukantadhar8784 3 года назад +1

    Excellently explained... Just looking for... Thank you very much sir :)

    • @Techsithtube
      @Techsithtube  3 года назад

      You are most welcome. thanks for watching!

  • @DAWIDTOMSIA
    @DAWIDTOMSIA 4 года назад

    Thx

  • @akshaykhobragade4871
    @akshaykhobragade4871 4 года назад

    Great work. Thank you so much. :)

  • @dbel431
    @dbel431 6 лет назад +1

    excellent

  • @blackness4954
    @blackness4954 7 лет назад +1

    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.

  • @ajayagrawal1090
    @ajayagrawal1090 4 года назад +1

    Impressed and subscribed just after this one.

    • @Techsithtube
      @Techsithtube  4 года назад +1

      Thanks for subscribing!

    • @ajayagrawal1090
      @ajayagrawal1090 4 года назад

      @@Techsithtube you won't go out of list never ever ever ever ever... 😋

  • @iamevanhe
    @iamevanhe 7 лет назад

    Could you also illustrate on passing an argument into the generator function via ".next(argument)"? I am very confused about this.

  • @pradipspeaks9395
    @pradipspeaks9395 3 года назад

    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😭). 🙏

  • @evgeniysurma8116
    @evgeniysurma8116 4 года назад

    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()

    • @mahyarekramian9040
      @mahyarekramian9040 3 года назад

      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

  • @nuwanthuduwage6869
    @nuwanthuduwage6869 2 года назад

    Sir, It means, request(url1) and request(url2) is working in a synchronous manner, blocking approach of execution? Please explain

  • @honghulin8810
    @honghulin8810 6 лет назад

    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!!

    • @Techsithtube
      @Techsithtube  6 лет назад +1

      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.

  • @boballen1232
    @boballen1232 7 лет назад +1

    should I learn Angular2 or React?!! I'm so torn, help!

    • @blackness4954
      @blackness4954 7 лет назад +1

      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.

  • @vlad981
    @vlad981 7 лет назад +2

    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"

    • @gpt-10
      @gpt-10 7 лет назад

      same question

    • @Dalendrion
      @Dalendrion 7 лет назад +4

      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.

    • @gpt-10
      @gpt-10 7 лет назад

      Dalendrion U R THE MAN ty

    • @Dalendrion
      @Dalendrion 7 лет назад

      Дмитрий Сухарев No problem, man.

  • @zoltobialozielony
    @zoltobialozielony 5 лет назад

    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!

    • @janumedia
      @janumedia 5 лет назад

      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

  • @animeshsharma8285
    @animeshsharma8285 7 лет назад

    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 !

    • @Techsithtube
      @Techsithtube  7 лет назад +1

      Lets say if you want to cancel a promise , using generators you can do it.

    • @Cyborgs1718
      @Cyborgs1718 7 лет назад

      Hello @techsith, could you provide an example of this case. I did not find anyone . this interest me very much :s

  • @SAURABHKUMARSUMAN
    @SAURABHKUMARSUMAN 6 лет назад

    We can do same with promises using async await then what is the difference?

    • @Techsithtube
      @Techsithtube  6 лет назад

      Async await is nothing but mix of promises and generators.

  • @muhammadinaammunir6761
    @muhammadinaammunir6761 3 года назад

    Where we can use this?

  • @iliketocode6986
    @iliketocode6986 3 года назад

    Love your thumb nails

  • @_cipher2039
    @_cipher2039 2 года назад

    gj

  • @pinikmanob7335
    @pinikmanob7335 7 лет назад

    let iterator = i [ Symbol.iterator ]() ;
    why wrapping Symbol.iterator within third brackets [ ] ?

    • @Techsithtube
      @Techsithtube  7 лет назад +1

      becase by ecma definition iterators are accessed like thisArray.prototype[@@iterator]()

  • @earth-to-brian
    @earth-to-brian 7 лет назад

    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?

    • @Techsithtube
      @Techsithtube  7 лет назад

      You could its perfectly file. However , every time you call next it has todo i[Symbol.iterator]() which is little bit expensive computation wise.

  • @danvilela
    @danvilela 3 года назад

    Why not use await instead of yield? I don't get why use this.

    • @ayikkathilkarthik4312
      @ayikkathilkarthik4312 3 года назад

      Generators was used before async/await. I think async/await uses generators under the hood.

  • @VishwaKolkar
    @VishwaKolkar 3 года назад

    if I call generator().next(); instead of iterator.next(); the value is always 1. Could you please make me understand?

    • @Techsithtube
      @Techsithtube  3 года назад +1

      Vishwa, generator() a new Iterator every time that is why generator().next() gives you 1 which is the first value.

    • @VishwaKolkar
      @VishwaKolkar 3 года назад

      @@Techsithtube thank you so much 🙏🏻

  • @hovhannesmanukyan1655
    @hovhannesmanukyan1655 4 года назад

    apri