“函数对象”是指类的对象,它在某种意义上是可调用的,并且可以在语言中被视为函数。例如,在 python 中:
class FunctionFactory:
def __init__ (self, function_state):
self.function_state = function_state
def __call__ (self):
self.function_state += 1
return self.function_state
>>>> function = FunctionFactory (5)
>>>> function ()
6
>>>> function ()
7
我的问题是 - FunctionFactory 和函数的这种使用是否会被视为闭包?