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

クロージャーについて

Posted at

クロージャーとは・・・

『関数』と、その関数の中に同封(enclosed)された、関数の「外」にある『変数』 これらの組み合わせのことである。
function greeting(greetingWord) {
 return function(otherWord) {
  return `${greetingWord}, ${otherWord}`;
 }
}

クロージャーのメリット

同類の処理をさせる関数を複数作る際に、記述を簡素化できる。
const sayGoodMorning = greeting("Ohayo");  //関数greetingに"Ohayo"が同封されている。
const sayWelcome = greeting("Youkoso");    //関数greetingに"Youkoso"が同封されている。

sayGoodMorning("Oni-Chan");  //"Ohayo, Oni-Chan"
sayWelcome("Nippon");        //"Youkoso, Nippon";
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?