When using middleclass I encountered a strange problem:
ParentClass = class('ParentClass')
function ParentClass:initialize(param)
self.param = param
end
Now this will work:
Child1 = class('Child1', ParentClass)
function Child1:initialize(param)
ParentClass.initialize(self, param)
end
But this wont:
Child2 = class('Child2', ParentClass)
function Child2:initialize(param)
ParentClass:initialize(param)
end
Creating Children like Child2 will result in a modification of param not for the single instance but for all children that inherit from ParentClass.
It took me quite a long time to identify this problem as I was sure that Object:function() is just syntactical sugar for Object.function(Object) and thus should be the same. This seems somehow not to be a problem of middleclass because a different OO library I used before showed similar problems...
What am I missing here?