Skip to content

Instantly share code, notes, and snippets.

@yljphp
Created August 20, 2018 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yljphp/84f3330bd9461c5a6d7a8b7a38f05cc1 to your computer and use it in GitHub Desktop.
Save yljphp/84f3330bd9461c5a6d7a8b7a38f05cc1 to your computer and use it in GitHub Desktop.
package main

import "fmt"

func main() {
    var fs = [4]func(){}
    for i := 0; i < 4; i++ {
        defer fmt.Println("defer i=", i)
        defer func() { fmt.Println("defer_closure i=", i) }()
        fs[i] = func() {
            fmt.Println("closure i= ", i)
        }
    }
    for _,f:=range fs {
        f()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment