Skip to content

Instantly share code, notes, and snippets.

@keshavab
Created March 31, 2016 10:39
Show Gist options
  • Save keshavab/8a8f95286cc2111aafe5e0cd03015f07 to your computer and use it in GitHub Desktop.
Save keshavab/8a8f95286cc2111aafe5e0cd03015f07 to your computer and use it in GitHub Desktop.
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