LoginSignup
1
0

More than 3 years have passed since last update.

argumentsプロパティの理解と使用例。

Last updated at Posted at 2019-03-23

argumentsプロパティたるものと、その使用例を、感覚的に理解するためのメモ。
【前提知識】for...of 文

argumentsとは?

  • 実引数のこと。
  • 関数を呼び出す際に入力される引数のこと。
  • 実引数は、関数が持つプロパティのうちのひとつなので、積極的に取得できる。
    • argumentsというプロパティに、配列とおなじ形で代入されている。
    • 例:第一引数 → arguments[0]

【使用例】

使用例.js
const xxx = ()=> {
  for ( let index in xxx.arguments ) {
    console.log ( xxx.arguments[index] );
  }
};
//これで、渡された引数をすべてconsoleに表示することができる。
//map関数の引数バージョンのようなイメージ。

xxx(1,2,3,4,5); 
//1
//2
//3
//4
//5

アロー関数では使用不可。

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