0
0

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

#JavaScript~クラスの基本
コピペして使ってください。
ES6を対象としています。

###コールバック関数

sample.js
//関数の定義
const greet = () => {
  console.log("Hello");
};

const call = (callback) => {
  console.log("コールバック関数の呼び出し");
  callback();
};

//関数の呼び出し
call(greet);
(出力結果)
コールバック関数の呼び出し
Hello

###コールバック関数(引数つきの関数を渡す)

sample.js
//関数の定義(コールバック時に引数を渡す)
const call = (callback) => {
  callback("John", 14);
};

//関数の呼び出し(関数を引数にもつ)
call((name, age) => {
  console.log(`${name}${age}歳です。`);
});
(出力結果)
Johnは14歳です。
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?