This section provides a quick description of object-oriented programming and prototype-based programming style.
There are three primary goals of object-oriented programming:
Encapsulation - The ability to conceal functional details of an object from objects that send messages to it
In other words, encapsulation is the ability to hide functional details of an object behind an interface
- a collection of methods for other objects to call.
Inheritance - The ability for an object of a derived type to inherit attributes and behaviors from a parent type.
Polymorphism - The ability for two objects of a parent type and a derived type to respond
to the same message from other objects with their own type specific behaviors.
These goals can be archived with two different programming styles:
Class-Based Programming - An object is created through an instantiation process based on
the specified class, which is statically defined with the structure and behavior of the resulting object.
Prototype-Based Programming - An object is created through a cloning process based on another
object serving as an prototype, which can be dynamically modified.
JavaScript is a prototype-based programming language which supports encapsulation, polymorphism, and inheritance
as described below:
Encapsulation - Functional details of an object are hidden inside properties and methods of the object.
Inheritance - Properties and methods of a parent type are inherited through a prototype object.
Polymorphism - Inherited properties and methods can be overridden by an object of a derived type
to respond the same interface specific to this object.
See other sections of this chapter for detailed descriptions and tutorial examples of JavaScript prototype-based
programming features.