0
1

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 1 year has passed since last update.

高階関数とは

高階関数とは
「関数を、引数や戻り値に持つ関数」
のことです。

function arrayWalk (array, f) {
    for (var key in array) {
        f(array[key]);
    }
}

function showData (value) {
    console.log(value);
}

var ary = ["Hi!","My Name is Tom!","Nice to meet you!"];
arrayWalk(ary,showData); 

Hi!
My Name is Tom!
Nice to meet you!

この場合、arrayWalkは引数に関数を持っていて実行しているため、高階関数になります。
また、呼び出される関数のことをコールバック関数と言います。

使いどころ

丸投げになってしまいますがこちらの記事がとても分かりやすかったです。
-- 高階関数を書いたら、中級者になれた気がした。を批判したら上級者になれた気がした。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?