Prototype-Dased Object-Oriented Programming Style
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 a prototype, which can be dynamically modified.
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.
Table of Contents
About This Book
Data Types, Variables and Expressions
Flow Control Statements
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
Server-Side and Client-Side Web Scripting
Introduction to Objects
►Defining Your Own Object Types
►Prototype-Dased Object-Oriented Programming Style
Defining Object Constructor Functions
Adding Properties and Methods to Objects
"for ... in" and "for each ... in" Statements
"prototype" Property of the Constructor Function Object
"instanceof" Operator - Determining Object Type
"typeof" Operator and Data Types
Inheritance of Properties and Methods through the Prototype Object Chain
Using Functions as "Function" Objects
Introduction to Built-in Object Types
W3C's Document Object Model (DOM) Specifications
Full Version in PDF/EPUB