Creating JavaScript Promises

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

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

  • @lucksmith-wd
    @lucksmith-wd Год назад

    Thank you! THANK YOU! I very rarely comment on videos, but this is just pure gold! It's not an easy concept, and you understand how much beginners may struggle with it. That's why your explanation is so clear. Thank you, again!

  • @Behold-the-Florist
    @Behold-the-Florist 4 года назад +4

    You're a very skilled teacher! Thanks, I really appreciate these videos!

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

    This is just too good. I have to admit I did'nt understand this concept from the tutorial bought from Udemy, thanks for your generousity and selflessness!

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

    Oh, it's the best js promise lesson I ever seen!

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

    Best tutorial on youtube

  • @chinonsoirobinda1272
    @chinonsoirobinda1272 6 месяцев назад

    Great teaching

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

    Thank you so much! This definitely helped me in my overall understanding promises and using them for a bootcamp project due next week...!

  • @IonutBucur-o_0
    @IonutBucur-o_0 6 лет назад +1

    Great as always... Thank you!!!

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

    Great work, keep it up, you earn respect......

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

    Thank You!

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

    great, clear explanation, thank you

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

    You r great teacher. But the problem is promises is really very difficult topic. So can you make few more tutorials on this

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

    Excellent! Merci beaucoup.

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

    very helpfull, thanks

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

    Having fun rewriting this in ES6:
    a.then(val => {console.log(val)}, (val) => {console.log("rejected: "+ val)});

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

    What is the difference between 'new Promise' and 'return new Promise'?
    Also you have written resolve with parenthesis "resolve()" and also without parenthesis "resolve". What is the difference here?
    Thank you for this tutorial.

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

      new Promise() creates the promise. If we add the return keyword in front of it, then it returns that promise from a function. When resolve is a parameter, it receives a function. It acts as a variable that receives a function. When we add parens at the end of it, this forces the function to be invoked.

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

    Please explain what this line of code does
    let promise = promise(executor(resolve,reject){......
    });
    What is the role of executor function in this context? how does it get called in back? what does it return ?

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

      Was your intent to use 'new Promise'? There is not enough of the code example to explain what is going on. We need to the declaration for the executor function and is promise suppose to be new Promise? Or is it a call to a function named promise?

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

      @@AllThingsJavaScript Ok let me re-phrase the question
      When we do
      let prom = new Promise(executor(resolve,reject){......
      });
      the Promise Constructor will be called and we will pass this entire executor function to this constructor right. So I want to ask 1) what that constructor will do with this executor function?
      2) How it will process this executor and what that constructor will return here? what will be that value.
      3) How we will use that return value
      Actually I see there are many things happening all at once like executor function is sent to the Constructor and the resolve or reject function are also getting called within the executor function at same time. This confuses me a lot with so many things happening.
      The sequence of events are looking haphazard to me so not able to trace it. With this feeling even if I understand how to write promise syntax not getting satisfied that I fully understood it

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

      @@tusharubale1788 Maybe this will help. When you create a promise, you need to pass a function into the constructor as you have said. The purpose of that function is so you can indicate with code how the promise will work. You indicate when the resolve function is called and when the reject function is called. You define that in the function.
      Now the act of creating a promise will return a promise. You can then act on that promise using the .then method to pass in a function for resolve and reject. Does that help?

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

    couldnt thank enough

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

    if somebody wanna use the last part with arrow syntax:
    let setTimeoutPromise = (time) => {
    return new Promise( (resolve, reject) => {
    if (isNaN (time)) {
    reject('a number is required
    please fill it again below')
    }
    setTimeout(resolve, time)
    })
    }
    setTimeoutPromise('kami')
    .then( () => {
    console.log('done')
    })
    .catch( (error) => {
    console.log(error)
    })

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

    When I use setTimeout as: setTimeout(resolve("done"),4000); --> this time it doesnt wait!! Why?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 лет назад +5

      The reason this happens is because you have included parentheses with your function name. Parentheses tell a function to invoke, so the function invokes before the setTimeout is even finished. You would need to do setTimeout(resolve, 4000);

    • @sevdamurat4455
      @sevdamurat4455 5 лет назад +1

      @@AllThingsJavaScript you are great! Thanks

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

    superrb !!!!!!!!!!!