title: Specifying metatables on new objects in Lua
body: <p><strong>Method/1</strong></p>
  
  <pre><code>Dog = {}
  function Dog:new()
    local newObj = {sound = 'woof'}
    return setmetatable(newObj,   { __index = self })
  end
  </code></pre>
  
  <p><strong>Method/2</strong></p>
  
  <pre><code>Dog = {}
  function Dog:new()
    local newObj = {sound = 'woof'}
    self.__index = self
    return setmetatable(newObj, self)
  end
  </code></pre>
  
  <p>Most of the times I have seen people using the <strong><code>self.__index = self</code></strong> method, which to me seems clumsy. Why pass the whole <code>Dog</code> object with all the additional methods which doesn't constitute a metatable to <code>setmetatable</code>? <strong>Method/1</strong> is good for setting the new objects's <code>metatable.__index</code> to the <code>Dog</code> object, it is also cleaner.</p>
  
  <h2>Is there a good reason to use <strong>Method/2</strong> instead of <strong>Method/1</strong>?</h2>
  
  <hr>
  
  <p>Some additional code to provide context, it works with both methods</p>
  
  <pre><code>function Dog:makeSound()
    print('I say ' .. self.sound)
  end
  
  mrDog = Dog:new()
  mrDog:makeSound()
  </code></pre>