Created
March 31, 2016 10:39
-
-
Save keshavab/8a8f95286cc2111aafe5e0cd03015f07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import "fmt" | |
func outer(name string) func() { | |
// variable | |
text := "Modified " + name | |
// closure. function has access to text even after exiting this block | |
foo := func() { | |
fmt.Println(text) | |
} | |
// return the closure | |
return foo | |
} | |
func main() { | |
// foo is a closure | |
foo := outer("hello") | |
// calling a closure | |
foo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment