3 ms·
Something of an aside: closures don't need to be "unnamed functions which capture their context", right? A function that "closes over" its context but is named
by fastball 7y ago
Something of an aside: closures don't need to be "unnamed functions which capture their context", right? A function that "closes over" its context but is named is still a closure, unless I'm wrong.
- wool_gather 7y agoYou're correct, but there's a bit of "linguistic drift" at play, I guess. The use of the term "closure" in the Swift ecosystem has come to refer almost entirely to the anonymous kind. (Side note, named functions in Swift are indeed also closures: let x = 10 func f() { print(x) } f() // Okay; prints 10 as you'd expect )
- fastball 7y agoYeah, that seems to be the case in the JS community as well – I see a lot of people referring to the arrow function syntax as "closures", even though named functions are closures in JS too.