当前位置:网站首页>js Promise

js Promise

2021-08-08 02:08:33 XFlyaa

var myFirstPromise = new Promise(function(resolve, reject){
    // When the asynchronous code executes successfully , We will call resolve(...),  Called when asynchronous code fails reject(...)
    // In this case , We use setTimeout(...) To simulate asynchronous code , The actual encoding might be XHR Request or request HTML5 Some of API Method .
    setTimeout(function(){
        //resolve(" success !"); // Code execution is normal !
      		reject("222222222");
    }, 250);
});

myFirstPromise.then(function(successMessage){
    //successMessage The value of is called above resolve(...) Method .
    //successMessage Parameters don't have to be string types , Here's just an example 
    document.write("Yay! " + successMessage);
},(e)=>{document.write("Yay! " + e);});

版权声明
本文为[XFlyaa]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210808020608674z.html

随机推荐