Preferences aside, the second example is the "right" one. In the first one, you're creating a new getName
function for every object. In 2, all objects created with this constructor will share the prototype/getName
. Change it in one place and it will change for every instance.
On special occasions (like complex inheritance chains) you might need to use the first, but be aware of it's drawbacks.
This blog post might help you understand prototypal inheritance better.