Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Javascript for dummies 4th edition - Veer E.V

Veer E.V Javascript for dummies 4th edition - Wiley publishing , 2004. - 387 p.
ISBN: 0-7645-7659-3
Download (direct link): javascriptfordummies2005.pdf
Previous << 1 .. 25 26 27 28 29 30 < 31 > 32 33 34 35 36 37 .. 118 >> Next

Objects defined by using HTML tags. This category includes documents, links, applets, text fields, windows, and so on. For the purposes of this book, JavaScript scripts are always attached to HTML documents. By using JavaScript, you can access any object defined in the HTML document to which a script is attached. (To see an example of a script accessing HTML objects, check out Listing 4-3 later in this chapter.)
Objects defined automatically by Web browsers. One example is the navigator object, which, despite its name, holds configuration and version information about whichever browser is currently in use, even if that browser happens to be Internet Explorer. (To see an example of a script accessing a browser object, check out Chapter 3.)
Objects that are built into JavaScript, such as Date and Number.
(To see an example of a script accessing built-in JavaScript objects, take a look at Chapter 3.)
Objects you yourself have created by using the JavaScript new operator.
(To see an example of how you can create and access your own objects using JavaScript, check out Chapter 3.)
Just like their real-world counterparts, software objects are typically associated with specific characteristics and behaviors. Because this is a computer
Part I: Building Killer Web Pages for Fun and Profit
topic, though, programmers can’t call these bits of information characteristics and behaviors. No, that would take all the fun out of it. Programmers call characteristics properties (or attributes), and they call behaviors methods — except for certain event-related behaviors whose names begin with on, such
as onLoad, onResize, and onSubmit. Programmers call these special on methods event handlers.
Properties and attributes are really the same thing, but some JavaScript programmers tend to differentiate between the following:
Properties (which belong to JavaScript objects)
Attributes (which are associated with HTML objects)
Because most of the JavaScript code that you write involves objects, properties, methods, and event handlers, understanding what these object-oriented terms mean is essential for folks planning to write their own scripts.
You can think of it this way:
^ Objects are always nouns.
^ Properties are adjectives.
^ Methods are verbs.
^ Event handlers are verbs with on tacked to their fronts.
Got it? Take a look at Table 4-1 to see examples of some common object definitions.
Table 4-1 Sample Object Definitions
Kind of Object Object (Noun) Property (Adjective) Method (Verb) Event Handler ("on" + Verb)
HTML button Such as name, type, and value click() onClick
HTML link Such as href, port, protocol, and so on (none) Such as onClick, onMouseOver, onKeyPress, and so on
HTML form Such as action , elements, length , and so on Such as reset() and submit() Such as onReset and onSubmit
Chapter 4: Getting Acquainted with the Document Object Model
Kind of Object Object (Noun) Property (Adjective) Method (Verb) Event Handler ("on" + Verb)
Browser Navigator Such as appVersion, appName, language, and platform javaEnabled() (none)
JavaScript Number Such as MAX_VALUE and MIN_VALUE toString() (none)
Programmer- defined customer Such as name, address, and credit-History Such as change-Address(), changeName(), and placeOrder() (none)
For sale by owner: Object properties
Properties are attributes that describe an object. Most of the objects available in JavaScript have their own set of properties. (Appendix C contains a listing of JavaScript properties arranged alphabetically.)
An image object, for example, is usually associated with the properties shown in Table 4-2.
Table 4-2 Properties Associated with the Image Object
Image Property Description
border The thickness of the border to display around the image, in pixels
complete Whether or not the image loaded successfully (true or false)
height The height of the image, in pixels
hspace The number of pixels to pad the sides of the image with
lowsrc The filename of a small image to load first
name The internal name of the image (the one you reference by using JavaScript code)
src The filename of the image to embed in an HTML document
vspace The number of pixels to pad the top and bottom of the image with
width The width of the image, in pixels
78 Part I: Building Killer Web Pages for Fun and Profit
At runtime, all object properties have a corresponding value, whether it’s explicitly defined or filled in by the Web browser. For example, consider an image object created with the HTML code in Listing 4-1.
Listing 4-1: Creating an Image Object with the HTML <IMG> Tag
<BODY>
<IMG SRC=”myPicture.jpg” NAME=”companyLogo” HEIGHT=”200” WIDTH=”500” BORDER=”1”>
</BODY>
Assuming that you have a file on your computer named myPicture.jpg, at runtime, when you load the HTML snippet into your Web browser and query the Image properties, the corresponding values appear as shown in Table 4-3.
You can query the properties by calling the alert() method; for example,
Previous << 1 .. 25 26 27 28 29 30 < 31 > 32 33 34 35 36 37 .. 118 >> Next