0%

https://hackernoon.com/6-reasons-why-javascripts-async-await-blows-promises-away-tutorial-c7ec10518dd9

Async/await 101

  • Async/await is a new way to write asynchronous code. Previous options for asynchronous code are callbacks and promises.
  • Async/await is actually built on top of promises. It cannot be used with plain callbacks or node callbacks.
  • Async/await is, like promises, non blocking.
  • Async/await makes asynchronous code look and behave a little more like synchronous code. This is where all its power lies.

Syntax

This is how you would implement it using promises

const makeRequest = () =>
getJSON()
.then(data => {
console.log(data)
return "done"
})

makeRequest()

And this is how it looks with async/await

const makeRequest = async () => {
console.log(await getJSON())
return "done"
}

makeRequest()

安装和使用

安装Webpack

sudo npm i webpack -g
mkdir demo
cd demo

npm init -y
npm i webpack webpack-cli -D

使用

在Webpack 4中,可以使用默认的配置,即零配置,不需要创建webpack.config.js文件。

阅读全文 »

Tutorials

Articles

Youtube

阅读全文 »