Anonymous Functions

The experienced JavaScript programmer is well versed in using anonymous functions. Since functions in JavaScript are a first-order concept, functions are passed around in JavaScript with abandon. Some even lament the callback hell of certain frameworks, but aesthetics aside, there can be no denying that anonymous functions are an important thing in JavaScript. So, the same must surely be true in Dart, right?

In JavaScript, an anonymous function omits the function name, using only the function keyword.

 
function​(i) {
 
if​ (i < 2) ​return​ i;
 
return​ fib(i-2) + fib(i-1);
 
}

We have already seen that the only difference between JavaScript and Dart functions is that the latter do not have the function keyword. It turns ...

Get Dart 1 for Everyone now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.