What is a 'Closure'?

前端 未结 23 1678
星月不相逢
星月不相逢 2020-11-22 08:02

I asked a question about Currying and closures were mentioned. What is a closure? How does it relate to currying?

23条回答
  •  暖寄归人
    2020-11-22 09:06

    A simple example in Groovy for your reference:

    def outer() {
        def x = 1
        return { -> println(x)} // inner
    }
    def innerObj = outer()
    innerObj() // prints 1
    

提交回复
热议问题