- 最終更新
- 2026/08/17
3秒でわかる
JavaScriptで `=>` を使って書く関数式。短く書けるうえ自分の this を持たないため、コールバック内で this がずれる問題を避けられます。
30秒図解
もう少し詳しく
どういうものか
アロー関数は=> という
const double = (n) => n * 2;引数が 1 つならreturn も {} も
function 式とのthis を持たない ことです。中で this をthis がarguments も持たず、new で
なぜ必要か
function でthis がsetTimeout(function () { this.name }) とthis はもうオブジェクトを指していません。以前は const self = this と.bind(this) を
アロー関数はmap や filter の
具体例
const items = [
{ name: "coffee", price: 480 },
{ name: "latte", price: 520 },
];
const names = items.map((i) => i.name);
const total = items.reduce((sum, i) => sum + i.price, 0);
// オブジェクトを返すときは丸カッコで包む
const toRow = (i) => ({ label: i.name, yen: i.price });
const timer = {
label: "注文受付",
start() {
setTimeout(() => {
console.log(this.label); // 注文受付
}, 1000);
},
};setTimeout の中の this が timer のままである
つまずきやすいところ
{} を書く(i) => { name.i } はundefined が({ ... }) と包みますthis はundefined やthis を使うthis にevent.currentTarget から取りますnew して似た用語との違い
| 書き方 | 自分の | new | arguments |
|---|---|---|---|
function 式 | 持つ | できる | ある |
| アロー関数 | 持たない | できない | ない |
| メソッド短縮記法 | 持つ | できない | ある |
覚え方
「矢印はthis をthis を


