Hacker News new | past | comments | ask | show | jobs | submit login

In the closure example does declaring a new variable and setting its value to the iterative or the thing being passed in, does that mitigate the pass by reference issue?



Yes.

    for i := 0; i < 10; i++ {
        i := i
        ...
    }
https://go.dev/play/p/P7TunJCL7RS


Thank you!

The example is brilliant. Thanks.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: