Prototype or inline, what is the difference?
<p>I am just learning Javascript and I was wondering, is using the prototype declaration, like this:</p>

<pre><code>function TSomeObj()
{
  this.name="my object";
}

TSomeObj.prototype.showname = function() {
  alert(this.name);
}
</code></pre>

<p>Basically the same as doing it like this:</p>

<pre><code>function TSomeObj()
{
  this.name="my object";
  this.showname = function() {
    alert(this.name);
  }
}
</code></pre>

<p>When I dump the object's properties I get the same result:</p>

<pre><code>TSomeObj (inline version) =
{ 
    'name': 'my object',
    'test': function
}

TSomeObj (prototype declaration) =
{ 
    'name': 'my object',
    'test': function
}
</code></pre>

<p>What exactly is the benefit of using prototype declarations? Except less cluttering and more orderly sourcecode perhaps.</p>

<p>Update: I should perhaps have made it more clear that it was the <em>final</em> result i was curious about. The end result is ofcourse the same (i.e both register a new function in the object prototype) - but the way they do it is wildly different. Thank you for all replies and info!</p>
