Mastering JavaScript Callbacks

Поделиться
HTML-код
  • Опубликовано: 26 дек 2024

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

  • @titot.5462
    @titot.5462 8 лет назад +46

    Are going to have another video to explain this video?

    • @esra_erimez
      @esra_erimez 8 лет назад +22

      I thought it was just me. I'm more confused now than before the video.

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

      s

  • @cafeta
    @cafeta 9 лет назад +7

    I have been programming in Java for 10 years and for me the Js callbacks, npm and budo blow my mind...
    thanks for this great video.

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

    At first I thought this is a really complicated example because i am new to functional programming, but then after watching this video over and over many times , and after doing different operations through different .txt files, i really understood callback functions. Love this video! For people who are completely new to functional programming, I would suggest watching a few beginner videos about .filter function, .map function, .reduce function, beginner videos about callback functions and working out a few basic examples on them (really important) and then watching this video to gain perfection on callbacks. This video is aptly titled 'Mastering JavaScript Callbacks'

  • @Aktunes47
    @Aktunes47 8 лет назад +36

    thanks for making callbacks more bearable! (...)

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

    Frickin' awesome explanation! I've been trying to understand callbacks for days now, but i finally "get it" thanks to you! I will pay it forward.

  • @kyleyasumiishi5652
    @kyleyasumiishi5652 6 лет назад +2

    This tutorial is what made callbacks finally click for me. Thanks a ton!

  • @BrianFrancoeur
    @BrianFrancoeur 8 лет назад +1

    Excellent tutorial! You presented this confusing topic in a straightforward, simple way, while demonstrating best practices for writing callbacks. Your video has helped me gain a much clearer understanding of Javascript callbacks and how to implement them:)

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

    Love the tut, but had to watch in a few times, and pause in places to follow.
    You're obviously a guru, I think maybe you're moving a little to quickly for this to be easy to follow.
    For the rest of you who don't agree... you're guru's as well.
    LOL Loved the tut... can't wait to see more.

  • @gondorzzz
    @gondorzzz 9 лет назад +5

    Came for call backs, stayed for bears.
    In all seriousness this helped a ton! Finally clicked for me.
    Thanks!

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

    It could not get any more clear. Thank you so much Kyle!

  • @ismael1589
    @ismael1589 9 лет назад +3

    Wow!! great lesson, I found it really helpful even tho I don't understand everything that is going on with node.js and some other stuff. I will study more and comeback to watch this video again and hopefully it will make more sense and I will learn even more. Thank you!

  • @VenturaPaul
    @VenturaPaul 8 лет назад +1

    This was the tut I was searching for. Thank you dude n.n

  • @rondunphy9433
    @rondunphy9433 8 лет назад +1

    This was helpful, Kyle, thank you.

  • @pranaysingh3938
    @pranaysingh3938 8 лет назад +1

    This was a really helpful tutorial, thanks a lot man !

  • @huitradoemm
    @huitradoemm 8 лет назад +13

    Dude, you're focusing too much on doing logic for your bears and nothing in the synchronous and asynchronous calls. Please try to think about the people who really would like to learn and master those calls. Thanks

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад +5

      Thanks for the feedback!

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

      ohh come now.. bears rule.. don't like it? film your own stuff and post it.. Kyle, you are fun to watch teaching.. keep it up, good job

  • @vikramjadhav4180
    @vikramjadhav4180 9 лет назад +1

    Oh my god!! that was a nice tutorial, Thank You :).
    Are you planning to do some node.js series?
    We will be happy.

    • @kylerobinsonyoung
      @kylerobinsonyoung  9 лет назад

      Vikram Jadhav Thanks! :D Yes! I have a bunch planned for node.js. Feel free to request anything specific here: github.com/shama/letswritecode/issues/1

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

    Thank you and greetings from Bulgaria.
    Please, one off topics question. Regarding the nowadays' fashion for architectural patterns, unit testing and breaking functions to small testable chunks, will it be possible to test compareBears() and next() inside their enclosing function ?? And so in all regards what would be their best place ??

  • @aquadestructor
    @aquadestructor 8 лет назад

    Awesome tut! I have some questions though. Any way I can contact you anywhere?

  • @Shubham_Gautam
    @Shubham_Gautam 8 лет назад +2

    this guy love bears, btw nice tutorial :)

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

    Kyle, that was an amazing video. I had a question though. Is the stuff written inside these functions synchronous ? Consider the compareBears function. Does the bear line run after the dict line, is that part synchronous ?

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

      Thanks! All lines in JS run synchronously. You only have to consider, does this sync line schedule a function call to run some time in the future aka asynchronously?

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

      Got it, thanks :)

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

    Please explain how it works more that why we use it. As someone from Java, I'm completely lost.
    function(err, bears) { *stuff*}

  • @BigBeesNase
    @BigBeesNase 9 лет назад +1

    Hello Kyle,
    I have a question for you. I may be silly, I don't know. But I would ask.
    Its related to the way you have written the code.
    If I am not wrong you have written it all in nested way(indirectly) like
    getBears
    readFile1
    readFile2
    compare(indirectly nested)
    right ??
    why didn't you write the readFile1, readFile2 and Compare function at the same level. like
    getBears{
    readFile1{}
    readFile2{}
    compare{}
    }
    getBearInvoked{}
    wouldn't that be correct.??
    About myself, I am just a new comer to node.js and JS. If you could answer this question, I would be great.
    Thanks in Advance,

    • @kylerobinsonyoung
      @kylerobinsonyoung  9 лет назад +1

      +Vikas Gautam Welcome to Node.js! This is because the functions I'm using are asynchronous. So if you called each function at the same level, readFile2 or the compare function will get called before readFile1 has finished.
      Let's pretend the file that readFile is reading a very large file and takes 10 seconds to read the entire file into memory. When you call readFile() it starts reading that file. Nanoseconds later, JavaScript then moves onto the next line and calls compare() even though readFile hasn't finished. It will only call the callback function to let you know it has finished, 10 seconds later.
      The alternative would be to use readFileSync(). That function is synchronous and your second example would work like that. When you call readFileSync() it will block the JavaScript process making your app stall for 10 seconds until it has finished reading the file. So for small, less often opened files that is ok. But for most operations, async functions are preferred to avoid blocking your application process.

    • @BigBeesNase
      @BigBeesNase 9 лет назад +1

      +Kyle Robinson Young
      Thanks Kyle Sir,
      You just nailed it with your explanation.
      When you said readfile1 and readFile2 are async, the whole story clicked in my mind.
      Your code is perfect in all sense.
      Thank you so much. :) :)

  • @mattviverette
    @mattviverette 8 лет назад +1

    I really enjoyed this video and these are great examples of callbacks, but it would have been nice to have a better explanation of callbacks themselves. Also, it would have been nice to see a few refreshes of the browser to demonstrate the bears loading in different orders. Or perhaps they never will because the file sizes don't change? Not sure...

  • @PhuNguyen-vw8es
    @PhuNguyen-vw8es 8 лет назад +1

    I notice you don't use semicolon in your javascript. Is this a good practice? Do you have any comments or idea behind your habit? Or did you read any article regarding this?
    By the way, nice tutorial!

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад

      Thanks! I did a video about why I don't use semicolons when teaching: ruclips.net/video/gsfbh17Ax9I/видео.html
      When I started with JavaScript, I was told that a lot of scary things would happen if I didn't use semicolons, so I always did. But then I began contributing to a project in which the author preferred omitting semicolons. After a year helping out on that project, none of those bad things happened. So now I personally don't use them and advocate for people to try both ways and use what feels best for them.

    • @PhuNguyen-vw8es
      @PhuNguyen-vw8es 8 лет назад +1

      Checked more of your vids and I think you have a nice obsession with bears :D

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад

      ʕ•͡ᴥ•ʔ/

  • @bmarty82
    @bmarty82 9 лет назад +7

    I hope you will use semicolons in your code soon....

    • @kylerobinsonyoung
      @kylerobinsonyoung  9 лет назад +1

      Bogdan Martinescu I just published a video which explains why I don't: ruclips.net/video/gsfbh17Ax9I/видео.html ;)

    • @kylerobinsonyoung
      @kylerobinsonyoung  9 лет назад +3

      +Mark Thompson FWIW, I'm less likely to hire someone if they have strong opinions on semicolons. It means they either don't know the language well enough or worse... they do know the language, have strong opinions on non-issues and will likely be toxic member on my team.
      I think Max Ogden said it best, "There are two types of people, those who have strong opinions on semicolons and those who don't. I only want to work with the latter."

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

      Kyle Robinson Young latter means sir? I'm New in webDev... you mean sir Kyle... it's better to work with a team who can explain when to use or not the semicolon? By the way awesome video sir.

    • @Tyrone-Ward
      @Tyrone-Ward 6 лет назад +1

      @@xarbyx2207 what?

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

    Great video! Thanks :)

  • @noherczeg
    @noherczeg 9 лет назад +1

    Nice vid as always, but I'm missing the application of bind() and apply() methods here :).

    • @kylerobinsonyoung
      @kylerobinsonyoung  9 лет назад +1

      +noherczeg Thanks! I covered bind/apply/call in an earlier video just about functions, check it out: ruclips.net/video/jEx9V4uUcg0/видео.html

    • @noherczeg
      @noherczeg 9 лет назад +1

      Will do thanks! :)

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

    I am sorry I am a newbie.. Just curious what did you mean by "any sync call is going to Block the thread"?? Great vid though !!

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

      JavaScript runs on a single thread. So a synchronous call will stop everything else until it finishes vs an asynchronous call will let other operations continue to run as the original call finishes.
      An analogy is, think of a line or queue at a bank as a thread. The bank teller, JavaScript, can only help one person, or call, at a time. There is only one line. Everything is fine until someone comes with a big bag of pennies and begins counting one at a time. The entire line needs to wait for that person to finish counting those pennies. That is synchronous.
      Now imagine they open up multiple lines. Now JavaScript is able to help other people in those other lines while that one person finishes counting their pennies. JavaScript can still only help one person at a time but no longer needs to wait for slow people in certain lines in order to help other people in other lines. That is asynchronous.

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

      Thanks much that analogy helps.. !!

  • @David-hf7zd
    @David-hf7zd 7 лет назад +1

    I really liked your video

  • @jbip11
    @jbip11 8 лет назад +1

    Great video! I subscribed. :)

  • @artiew8718
    @artiew8718 8 лет назад

    thank you. i am growing tired of people using external modules as the panacea.

  • @dddrrr7139
    @dddrrr7139 8 лет назад

    where can i watch the video that explains the image() function being called? is there a way to show an image to the screen without having to include an image() function?

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад

      new Image() is a browser API to create an image tag: developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image
      Another way is to create the element instead:
      var img = document.createElement('img')
      img.setAttribute('src', 'image.jpg')
      document.body.appendChild(img)
      But var img = new Image() does the same thing and is shorter.

    • @dddrrr7139
      @dddrrr7139 8 лет назад

      thanks. so thats all you need to print an image onto your website. the built in html 5 image function image()

  • @tumvoodoo
    @tumvoodoo 8 лет назад +1

    Man, please add panda to the list of bears "We bare bears". btw, love your vids!

  • @Purplejacket
    @Purplejacket 8 лет назад

    I'm having a problem running the image loading example. For some reason, it can't find the Image() constructor.
    var img = new Image()
    ^
    ReferenceError: Image is not defined
    My code appears to be exactly the same as shown in the video. Any idea what the problem could be?
    Thanks in advance.

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад

      +Purplejacket Are you running it on a browser in the client side? Because Image is not available in Node.js on the server side so it will say Image is not defined.

    • @Purplejacket
      @Purplejacket 8 лет назад +1

      +Kyle Robinson Young
      Yeah, I was running it on the server side. Thanks for the fast feedback.

  • @FranciscoValenzuela92
    @FranciscoValenzuela92 9 лет назад +1

    Great video!

  • @cosorxndrw
    @cosorxndrw 9 лет назад +14

    Place those god damned semicolons!!! :D
    Nice tut, keep it up XD

    • @kylerobinsonyoung
      @kylerobinsonyoung  9 лет назад

      Cosor Alexandru Thanks!

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

      I have almost totally abandoned using semicolons in javascript. You rarely need them.

  • @tomyang7788
    @tomyang7788 8 лет назад

    what sofware did u use ?

  • @whiskey4609
    @whiskey4609 8 лет назад

    where is Image coming from? when you do image = new Image

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад +1

      It's a global variable provided by the browser: developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image

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

    fs.readfile(filepath,function(err, bears){
    if(err) return done(err)
    }
    If there is err in above code, will done cb be executed with err parameter and we get the error message OR
    it will just return the done cb with err something like:
    var returnvalue= getBears('bears.txt',function(err,bears)
    {
    console.log(bears);
    }
    and after we can execute:
    returnvalue();

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

      getBears() is async, so we don't use anything it returns. Instead we only rely on the callback we gave it to be called with an err or bears. return is only used in that function to escape early, like a break in a loop.
      You can also return a value in an async function but generally it's better to pick only one to avoid confusion: return with sync function and call a callback with async functions.

  • @Unitazy
    @Unitazy 8 лет назад +1

    Thank you Sir, atom ftw

  • @deepmondal8564
    @deepmondal8564 8 лет назад +1

    Good tutorial men!!!!!!

  • @juliocgfreitas
    @juliocgfreitas 9 лет назад +1

    great man!
    cheers

  • @whiskey4609
    @whiskey4609 8 лет назад

    whats with the bears why does everyone use bears as an example??

    • @kylerobinsonyoung
      @kylerobinsonyoung  8 лет назад +7

      The bear lobby is very influential in the government. I am required by law to use bears as examples when writing code.

    • @XD-ci6jl
      @XD-ci6jl 8 лет назад

      lmfao, great video dude.

  • @mmahgoub
    @mmahgoub 9 лет назад +1

    What is it with bears?! lol!

  • @MLCHRL
    @MLCHRL 8 лет назад +1

    thanks.

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

    i cant believe you didn't call your 'compareBears'-function 'comBear' :p

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

      I'm going to now regret that for the rest of my life. Thanks.

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

    Please zoom in or increase font size next time

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

    Very good explanation but the video quality is very poor

  • @SudeepMakwana
    @SudeepMakwana 8 лет назад +1

    thanks alot ..

  • @koushikram1992
    @koushikram1992 8 лет назад +1

    thank u :)

  • @casey-zd5mj
    @casey-zd5mj 7 лет назад +1

    bears cares dares snares pares

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

    thx nice code

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

    semi
    fking
    colons

  • @pepeback
    @pepeback 8 лет назад

    Using Node to explain callbacks not a good thing. Using done() without explaining much of it. This video is just for showing off.

  • @Adapt-wj5gi
    @Adapt-wj5gi 7 лет назад +1

    Man your explanation for beginners about asynchronous callbacks is terrible ..

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

      Thanks! Very kind of you to say!

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

      That video is great! Thanks for sharing!
      My videos are purposefully short and focused on specific topics with the intent for viewers to continue learning about the subject more in depth through other resources. As I believe a beginner is not as likely going to watch a 30 min talk on the event loop just to understand how to use callbacks but to each their own.

    • @Adapt-wj5gi
      @Adapt-wj5gi 7 лет назад

      But he should!