Created
February 18, 2020 19:45
-
-
Save manderly/bce9b45740c85897377f5f1df9a26997 to your computer and use it in GitHub Desktop.
Simple closure in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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