1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptのシグネチャの読み方

Posted at

前置き

axiosというHTTPクライアントのREADMEを読んでいると、以下のようなシグネチャがでてきた。
どう読むんだろう、、🤔

axios#post(url[, data[, config]])

axiosのGitHub
https://github.com/axios/axios

断っておくとこの書き方はaxiosだけに出てくるものではなく、
MDNのようなサイトでもこのような記法が随所にでてくる。

MDNのforEach()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

というわけで調べた。

結論

結論、[]の部分は任意ということになる。

axiosの例であれば、以下のような書き方は問題ない。

axios#post(url)

axios#post(url, data)

axios#post(url, data, config)

反対に以下のようなdataを飛ばして、その先のconfigを指定するといった書き方はできない。

axios#post(url, config)

参照

1
2
0

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?