Skip to content

Instantly share code, notes, and snippets.

@keshavab
Created March 31, 2016 10:31
Show Gist options
  • Select an option

  • Save keshavab/8f4195dc68bb3200ef3c3172976bb3aa to your computer and use it in GitHub Desktop.

Select an option

Save keshavab/8f4195dc68bb3200ef3c3172976bb3aa to your computer and use it in GitHub Desktop.
closure introduction
package main
import "fmt"
func outer(name string) {
// variable in outer function
text := "Modified " + name
// foo is a inner function and has access to text variable, is a closure
// closures have access to variables even after exiting this block
foo := func() {
fmt.Println(text)
}
// calling the closure
foo()
}
func main() {
outer("hello")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment