Two ways of creating javascript objects, which one should I use?
<p>These are the ways of creating javascript objects:</p>

<pre><code>function apple(optional_params) {
    this.type = "macintosh";
    this.color = "red";
    this.getInfo = function () {
        return this.color + ' ' + this.type + ' apple';
    };
}

var apple = {
    type: "macintosh",
    color: "red",
    getInfo: function() {
        return this.color + ' ' + this.type + ' apple';
    }
}
</code></pre>

<p>I really prefer the latter one most since it's Json syntax, but I've seen more of the first one than the latter one.</p>

<ul>
<li>Are there any differences between them functionally?</li>
<li>Could each of them be extended, inherited and cloned/copied?</li>
<li>In the latter one I could easily create nested elements, is this possible with the first one?</li>
<li>In the latter one I can't pass optional parameters?</li>
<li>Are they serving different purposes? If yes, could you give scenarios where I would use either of them.</li>
</ul>
