```golang
package main
import (
"fmt"
"strconv"
)
type Attach func(string) string
func (a Attach) loopTimes(n int) string {
for i := 1; i < n; i ++ {
a(strconv.Itoa(i))
}
return a(strconv.Itoa(n))
}
func newAttach() Attach {
basic := "Begin"
return func(s string) string {
basic = fmt.Sprintf("%s\n%s", basic, s)
return basic
}
}
func main() {
a1 := newAttach()
fmt.Println(a1.loopTimes(10))
}
```
输出是:
```shell
Begin
1
2
3
4
5
6
7
8
9
10
```
你理解了么?
有疑问加站长微信联系(非本文作者))