Introduction to Objects
Objects are the foundation of JavaScript.
Therefore, an understanding of objects as they relate to web development
is essential to understanding JavaScript.
Everything we do with JavaScript relies on one or more objects.
An object is simply a collection of Properties, Methods and
Events. Let's use a Telephone as an example.
Objects have Properties:
You might describe an telephone by size,
color, style (wall, desk, cordless or cellular, Rotary or
Touch Tone.
Computer related objects such as buttons,
text boxes and even the web page itself also have properties such
as size, color or name, just like the telephone.
Properties are usually designated by nouns.
Objects have Methods:
Methods are what the object does.
For example, a telephone is a communications device that
converts sound waves into electrical impulses that can be sent
great distances. It can also convert these electrical
impulses back into sound so we can hear the message being
transmitted.
Computer related objects also have methods
such as open, write, close and focus. Methods denote
action and are therefore usually designated by verbs.
Objects
have Events:
A telephone rings notifying you that
someone wants to talk to you. It is the up to you to
decide
how you will respond to this event (answer or ignore).
Computer related objects also have events
such as onclick,
ondblclick,
onmouseover and onmouseout.
We use these events to start our script running.
When an event occurs it is referred to as firing (e.g., user clicks on
button and that buttons onclick event fires), the event is sent to the operating system which in turn
sends it to the appropriate software. In this case the browser.
If the browser has been notified to listen for this event or
use (capture) it,
the browser will notify the scripting engine which script to run.
No matter how simple, or how complex a script is, all we ever
do is work with, or manipulate and exploit,
properties,
methods and events of
objects.
|