How do promises work in JavaScript?

前端 未结 4 544
时光取名叫无心
时光取名叫无心 2020-11-28 09:06

I just implemented my first function that returns a promise based on another promise in AngularJS, and it worked. But before I decided to just do it, I spent 2 hour

4条回答
  •  执念已碎
    2020-11-28 09:33

    For the simplicity to understand about the promises in Javascript. You can refer below example. Just copy paste in a new php/html file and run.

    
    
    
    
    
    
    
    
    
    
    
    
    1. Click on Test button,
    2. It will create new promise,
    3. if condition will be true it fulfill the response,
    4. after that promise.then called and based on the fulfill it will print the result.
    5. In case of reject promise.then returns the error message.

提交回复
热议问题