0% found this document useful (0 votes)
12 views

Properties.: A B C A

Prototype objects can reference other prototype objects to form a prototype chain, which allows for inheritance and shared properties between objects. ECMAScript uses prototype-based inheritance through prototype chains rather than classes, allowing objects to inherit common properties from other objects and define their own unique properties. This achieves code reuse without duplicating shared functionality in every object.

Uploaded by

Tiru Battu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Properties.: A B C A

Prototype objects can reference other prototype objects to form a prototype chain, which allows for inheritance and shared properties between objects. ECMAScript uses prototype-based inheritance through prototype chains rather than classes, allowing objects to inherit common properties from other objects and define their own unique properties. This achieves code reuse without duplicating shared functionality in every object.

Uploaded by

Tiru Battu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Prototype objects are also just simple objects and may have their own prototypes.

If a prototype
has a non-null reference to its prototype, and so on, this is called the prototype chain.
A prototype chain is a finite chain of objects which is used to implement inheritance and shared
properties.
Consider the case when we have two objects which differ only in some small part and all the
other part is the same for both objects. Obviously, for a good designed system, we would like
to reuse that similar functionality/code without repeating it in every single object. In class-based
systems, this code reusestylistics is called the class-based inheritance you put similar
functionality into the class A, and provide classes B and C which inherit from A and have their
own small additional changes.
ECMAScript has no concept of a class. However, a code reuse stylistics does not differ much
(though, in some aspects its even more flexible than class-based) and achieved via
the prototype chain. This kind of inheritance is called a delegation based inheritance (or, closer to
ECMAScript, a prototype based inheritance).
Similarly like in the example with classes A, B and C, in ECMAScript you create objects: a, b,
and c. Thus, object a stores this common part of both b and c objects. And b and c store just
their own additional properties or methods.

You might also like