class prototype object vs class instance properties

liorean liorean at
Sat Aug 18 02:21:17 PDT 2007

On 17/08/07, Garrett Smith <dhtmlkitchen at> wrote:
> What is the difference between a class's prototype object and it's
> instance properties?

Prototype properties are fallbacks if the property does not exist on
the instance.

> class A {
>   var x : uint = 10; // instance property.
>   prototype var x : uint = 20; // another instance property in the
> prototype chain.
> }
> class B extends A { }
> My understanding is that the result would be:
> new B().x; // result is 20.
> What would be the benefit of a class having a prototype over 9instance
> properties/methods?

Prototype properties can be shadowed by instance properties without
being changed, prototype properties are fallbacks if the instance
property does not exist, and prototype properties are not part of the
actual instance, so can be used as memory footprint reduction if one
has lots of instances that don't need separate values for that
instance property.
David "liorean" Andersson

More information about the Es4-discuss mailing list