JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.10

Prototype-Based Programming Features in JavaScript

This section provides a list of some prototype-based programming features in JavaScript, like constructor function, prototype object, object properties and methods.

As I mentioned in the previous section, JavaScript is a prototype-based programming language. It supports object-oriented programming through a number of features:

  • There is no class definitions. JavaScript does not use classes.
  • Objects are created from constructor functions.
  • Each constructor function represents a unique object type.
  • A constructor function can define properties and methods for all objects created from this constructor function.
  • Each constructor function can be associated with a prototype object.
  • An object automatically inherits properties and methods of the prototype object associated with its constructor function.
  • Each object can its own properties and methods.
  • Inherited properties and methods can be overridden by an specific object or the prototype object.
  • There is one built-in constructor function called "Object()" that provides the base object type for all other object types.
  • All functions are actually objects created from the base constructor function called "Function()".
  • All objects of all types are inheriting properties and methods defined by the base constructor function "Object()".
  • There are several major built-in objects, representing constructor functions, including "Array()", "Boolean()", "Date()", "Error()", "Function()", "Math()", "Number()", "Object()", "RegExp()", "String()".
  • There seems to be no multi-inheritance support in JavaScript.
  • Private properties and methods are supported in JavaScript in a special way.

Several tutorial examples will be provided later in this chapter to illustrate some of those features.

Sections in This Chapter

Prototype-Dased Object-Oriented Programming Style

Prototype-Based Programming Features in JavaScript

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

Dr. Herong Yang, updated in 2008
Prototype-Based Programming Features in JavaScript