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 3 years have passed since last update.

コールバック関数

Posted at

引数に関数を渡す。
Javaから始めた自分としては考えられない。

var callBackTest1 = (callback) => {
    console.log("1");
    callback();
};

var callBackTest2 = () => {
  console.log("2");
}

// 呼び出し
callBackTest1(callBackTest2);
// "1"
// "2"

上記を無名関数に置き換えることもできる。

callBackTest1(function() {
    console.log("2");
});    

引数がある関数を呼ぶ場合


var callBackTest1 = (callback, name) => {
    console.log("1");
    callback(name);
};

var callBackTest2 = (name) => {
  console.log(name);
}

callBackTest1(callBackTest2, "hoge");
// 1
// "hoge"

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?