Trying to wrap my head around objects, constructors and prototypes
<p>Consider the following code:</p>

<pre><code>function Robot(weapon) {
    this.weapon = weapon;
    this.fire = function() {
        alert('Firing ' + this.weapon + 'projectile.');
    };
}

var gunRobot = new Robot('gun');
</code></pre>

<p>vs.</p>

<pre><code>function makeRobot(weapon) {
    return {
        weapon: weapon,
        fire: function() {
            alert('Firing ' + this.weapon + 'projectile.');
        }
    };
}

var laserRobot = makeRobot('laser');
</code></pre>

<p>So, if I understood right, the main difference between these two is that in the first example, gunRobot has a constructor property which points to Robot, whereas in the second example, laserRobot has a construtor property which points to Object. Both don't add anything to their prototype, right?</p>

<p>Now, if I change the first example to:</p>

<pre><code>function Robot(weapon) {
    this.weapon = weapon;
}

Robot.prototype.fire = function() {
        alert('Firing ' + this.weapon + 'projectile.');
};

var gunRobot = new Robot('gun');
</code></pre>

<p>gunRobot's constructor property points to the Robot constructor, whose prototype property has a property fire. Now, if I call</p>

<pre><code>gunRobot.fire();
</code></pre>

<p>as, gunRobot doesn not have a fire property, the next prototype up in the prototype chain is visited and checked for a fire property, right?</p>

<p>I'm mainly a Java programmer, so it's quite hard to wrap my head around JS notion of object-orientation :-).</p>
