![ECMAScript Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/58/36700058/b_36700058.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open your command-line application and navigate to your workspace.
- Create a new folder named 03-01-creating-and-waiting-for-promises.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js file that creates a promise and logs messages before and after the promise is created, as well as while the promise is executing and after it has been resolved:
// main.js export function main () { console.log('Before promise created'); new Promise(function (resolve) { console.log('Executing promise'); resolve(); }).then(function () { console.log('Finished promise'); }); console.log('After promise created'); }
- Start your Python web server and open the following link in your browser:
http://localhost:8000/.
- You will see the following output:
![](https://epubservercos.yuewen.com/C944E7/19470395501577006/epubprivate/OEBPS/Images/7bdb1f62-5603-4bd8-a3dd-15c0de1a0388.png?sign=1738866571-xHCeYMGkqDHMNKiJqESX0iQrsH6t0v3Y-0-eaa7ecf3664eb3e90a427ecf48059747)