Which way is better?
This
Dog = {}
function Dog:new()
newObj = {sound = 'woof'}
self.__index = self
return setmetatable(newObj, self)
end
function Dog:makeSound()
print('I say ' .. self.sound)
end
mrDog = Dog:new()
mrDog:makeSound()
or this
Dog = {}
function Dog:new()
newObj = {sound = 'woof'}
return setmetatable(newObj, {__index = self})
end
function Dog:makeSound()
print('I say ' .. self.sound)
end
mrDog = Dog:new()
mrDog:makeSound()
The first one is how everyone does it but the second one is less confusing and make more sense to me
Is there any issue in second one?