Skip to content

Instantly share code, notes, and snippets.

@manderly
Created February 18, 2020 19:45
Show Gist options
  • Save manderly/bce9b45740c85897377f5f1df9a26997 to your computer and use it in GitHub Desktop.
Save manderly/bce9b45740c85897377f5f1df9a26997 to your computer and use it in GitHub Desktop.
Simple closure in Dart
// Closure example, sort of a companion to my JS example:
// https://repl.it/@MandiGrant/JSClosureExample
// combineNames is a function that returns a function.
var combineNames = (firstName) {
return (lastName) => firstName + ' ' + lastName;
};
void main() {
// Call it with a first name and then call *that* function with a last name
var returnedFunction = combineNames('Anne');
print(returnedFunction); // prints "{Closure 'main__closure'}"
var fullName = returnedFunction('Jones');
print(fullName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment