We want to make this open-source project available for people all around the world.

Help to translate the content of this tutorial to your language!

BuyEPUB/PDF
Share
back to the lesson

Rewrite with arrow functions

Replace Function Expressions with arrow functions in the code below:

function ask(question, yes, no) {
 if (confirm(question)) yes();
 else no();
}
ask(
 "Do you agree?",
 function() { alert("You agreed."); },
 function() { alert("You canceled the execution."); }
);
function ask(question, yes, no) {
 if (confirm(question)) yes();
 else no();
}
ask(
 "Do you agree?",
 () => alert("You agreed."),
 () => alert("You canceled the execution.")
);

Looks short and clean, right?

AltStyle によって変換されたページ (->オリジナル) /