Properties are usually used to describe the object in some way.
57
C H A P T E R 3
??? A method is a function that is attached to an object. A method can accept parameters,
often referred to as arguments, and can return values back. Methods are used to interact
with the object in some way, making it act and react. Methods are often used to
change the state (that is, a property) of an object. While some languages, such as Java,
require the use of methods to modify properties (also known as getter and setter methods
because they get and set property values), JavaScript enables you to modify
properties directly. This negates the need for overly simple methods that just change
the value of a property.
??? Encapsulation hides implementation details and restricts access to certain functionality
based on what needs to access it. For example, you might have an animation object
that stores a list of elements to be moved around the screen. Your code might depend
on that list to be in a certain order, so you??™d want to limit others from being able to
access it. In other languages, encapsulation is often accomplished through private,
protected, and public functions.
??? Inheritance, which is the subclassing of objects, enables you to define subclasses that
can inherit properties and methods from a parent object while offering up its own. The
document object model (DOM), for example, exhibits this behavior.
Pages:
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112