LoginSignup
2
0

More than 3 years have passed since last update.

async(Promise)のthen()内の関数の引数の省略

Last updated at Posted at 2020-01-21

備忘録として書き記す。

nuxt.jsのコードを追っていたところ下記の部分で引っかかる。

.nuxt/client.js
// Create and mount App
createApp().then(mountApp).catch(errorHandler)

コードの内容から察するにmountAppにはcreateAppの結果が引数として渡されているように見えるので実際に確かめてみた。

main.js
const first = async () => {
  return 'first'
}

const second = (arg) => {
  console.log('second')
  console.log(arg)
}

// then内の関数に自動的に引数が渡される
first().then(second)
// second
// first

// 省略しないパターン
first().then((f) => second(f))

どなたかこのような振る舞いの名称や公式で記載されているページをご存知であれば、コメントで教えていただけると幸いです。

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0