HTML and CSS Reference
In-Depth Information
Objects and Prototypal
J avaScript is an object oriented programming language. However, unlike most
other object oriented languages, JavaScript does not have classes. Instead, JavaScript
offers prototypes and prototype-based inheritance in which objects inherit from other
objects. Additionally, the language offers constructors—functions that create ob-
jects, a fact that often confuses programmers and hides its nature. In this chapter
we'll investigate how JavaScript objects and properties work. We'll also study the
prototype chain as well as inheritance, working through several examples in a test-
driven manner.
7.1 Objects and Properties
JavaScript has object literals , i.e., objects can be typed directly into a program using
specific syntax, much like string ( "a string literal" ) and number literals
( 42 ) can be typed directly in a program in most languages. Listing 7.1 shows an
example of an object literal.
Listing 7.1 An object literal
var car = {
model: {
year: "1998",
make: "Ford",
model: "Mondeo"
Search WWH ::

Custom Search