To save the function name in a variable and call it later, you have to wait until reflection appears in Dart (or get creative with noSuchMethod ). However, you can store functions directly in variables, for example, in JavaScript
main() {
var f = (String s) => print(s);
f("hello world");
}
and even embed them, which is useful if you do a recursion:
main() {
g(int i) {
if(i > 0) {
print("$i is larger than zero");
g(i-1);
} else {
print("zero or negative");
}
}
g(10);
}
main() {
var function;
function = (String s) => print(s);
doWork(function);
}
doWork(f(String s)) {
f("hello world");
}