animals = {}
function animals:clone ()
local new_table = {}
for k, v in pairs (self) do
new_table[k] = v
end
return new_table
end
function animals:setup (fields)
self.fields = fields
end
function animals:display()
tprint (self)
end
dog = animals:clone()
dog.name = "Harry"
dog.age = "5"
dog:display()
in this example everything works fine, but if i had there a method :name i could not assigne animal its name.
i see 2 solutions. add _ to every class method like
animals:_display() and animals:_name()
and store all animal details like that
dog.details.name = "Harry"
which approach is better?