Prototypes and Inheritance
<p>Recently I started learning Javascript as I am comming from Java world. I got this book called <a href="http://rads.stackoverflow.com/amzn/click/0596805527" rel="nofollow">JavaScript The Definitive guide.</a>. I am now a little confused about Prototypes and Inheritance. I want to know what is difference between setting a function to object property and functions prototype. From the book example :</p>

<pre><code>function Rectangle(w, h) {
this.width = w;
this.height = h;
this.area = function( ) { return this.width * this.height; }
}
</code></pre>

<p>With this new version of the constructor, you can write code like this:</p>

<pre><code>// How big is a sheet of U.S. Letter paper in square inches?
var r = new Rectangle(8.5, 11);
var a = r.area( );
</code></pre>

<p>This solution works better but is still not optimal (why) . Every rectangle created will have
three properties ( Yes, and so what ? ). The width and height properties may be different for each
rectangle, but the area of every single Rectangle object always refers to the same
function (someone might change it, of course, but you usually intend the methods
of an object to be constant). It is inefficient to use regular properties for methods
that are intended to be shared by all objects of the same class (WHY ??? What is the problem ? ) (that is, all objects
created with the same constructor).</p>
