Go使用闭包

在这里, 我们创建一个匿名函数, 该函数充当函数闭包。没有名称的函数称为匿名函数。

闭包是从其主体外部引用参考变量的函数。该函数可以访问并分配给引用的变量。

去关闭示例

package main
import (
   "fmt"
)
func main() {
   number := 10
      squareNum := func() (int){
      number *= number
      return number
   }
   fmt.Println(squareNum())
   fmt.Println(squareNum())
}

输出:

100
10000
微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_50071.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?