How to achieve JavaScript Object inheritance?
<p>I want create a new JavaScript object based on an existing JavaScript object.<br>
Till now my research led me to jQuery extend function.<br>
<br>example:</p>

<pre><code>var object1 = {
    name:'same name',
    age:'1',
    occupation:'programmer'
}
var object2 = {
    name:'same new name'
}
</code></pre>

<p>Now, when I call:</p>

<pre><code>$.extend({},object1,object2);
</code></pre>

<p>it works perfectly, my problem is when I have object member within the object!<br></p>

<pre><code>var object1 = {
    name:'same name',
    age:19,
    occupation:'programmer',
    parent:{
        name:'parent name',
        age:35
    }
}
var object2 = {
    name:'same new name',
    parent:{
        age:40
    }
}
</code></pre>

<p>Now, when I call</p>

<pre><code>$.extend({},object1,object2);
</code></pre>

<p>object1.parent is:</p>

<pre><code>{
    age:40
}
</code></pre>

<p>I want it to be:</p>

<pre><code>{
    name:'same new name',
    age:40
}
</code></pre>

<p>Is there a way to achieve this?</p>
