Books
in black and white
Main menu
Home About us Share a book
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. Quick Reference - Vander

Vander Javascript for dummies. Quick Reference - Wiley Publishing, 2002. - 115 p.
Download (direct link): javascriptquickreference2002.pdf
Previous << 1 .. 29 30 31 32 33 34 < 35 > 36 37 38 39 40 41 .. 72 >> Next

For more details about using functions in JavaScript, see JavaScript For Dummies, by yours truly, published by IDG Books Worldwide, Inc.
Methods: Hov) an Object BehaVes
This part lists every method available to you in JavaScript.
/it this part...
u* Getting familiar with the methods available to you in JavaScript
v* Deciding how (and when) to call each method
92 abs
Methods
A method is just like a function (see also Part V for more on functions). Unlike functions, however, methods access only one object’s data — the object with which the method is associated. A method’s name is typically a verb that describes what the method does to its associated object (for example, bl i nk(), bl ur (), and с 1 i с к ()). As you see in the upcoming examples, you invoke methods by specifying the fully qualified (that is, the complete) name of the object to which the method belongs.
Take the с 1 i с к () method, for example. If you have three buttons on a form — buttonOne, buttonTwo, and buttonThree, all of which support the cl i ck() method, how would the JavaScript interpreter translate с 1 i с к () by itself? It couldn’t! You have to include the method to specify which button you want to click on, like this: document.myForm.buttonOne.cl i ck().
The only exception to this format is the wi ndow object, which doesn’t usually need to be specified explicitly when you call one of its methods.
Several of the Stri ng methods that you run across in this part are identical to selected HTML tags in terms of their results. For example, two ways exist to make text on a Web page appear in big font, and each way is equally effective:
♦ A JavaScript statement: document.write(" Here is
some bi g text".bi g())
♦ An HTML statement: <BIG>Here is some big
text</BIG>
Whenever you have a choice between using an HTML tag and a JavaScript statement to perform the same task, ask yourself whether you want to perform the task based on some user input. If so, opt for the JavaScript statement; if not, the HTML tag will suffice.
abs
Use the abs () method of the Math object to return the absolute value of a number.
Syntax:
Math.abs(number)
Example:
var myResult = Math.abs(l)
anchor 03
fl
fl
fl
fl
fl
fl
fl
acos
Use the acos () method of the Math object to return the arc cosine (in radians) of a number.
Syntax:
Math.acos(number)
Example:
var myResult = Math.acos(l)
atert
Use the a 1 ert () method of the wi ndow object to display a pop-up dialog box that contains two elements: a message that you define and an OK button.
Syntax:
a 1e rt("message")
Example:
alert("Your- order total is " + getOrderTotal())
anchor
Use the a n с h о r () method of the String object to identify a string as an HTML anchor. After you define a string as an anchor, you can use the string as the target for a hypertext link. See also the “Link” section in Part III.
Syntax:
stri ng.anchorianchorName)
Example:
"Table Of Contents".anchor("T0C_anchor")
Using the a n с h о r () method lets you define an anchor inside a JavaScript script; the <A> . . . </A> tag pair is the way to define an anchor in HTML. For example, you can replace the preceding example with the following HTML code:
<A NAME="TOC_anchor">Table of Contents</A>
Most programmers use HTML tags to define anchors unless they want to create a link on the fly, based on some user input. To define a link based on user input, savvy JavaScript authors use the a n с h о r () method instead.
% asin
asin
Use the a s i n () method of the Math object to return the arc sine (in radians) of a number.
Syntax:
Math.asin(number)
Example:
Math.asin(l)
atan
Use the atan () method of the Math object to return the arc tangent (in radians) of a number.
Syntax:
Math.atan(r7i//77ber)
Example:
Math.atan(l)
atan 2
Use the atan2 () method of the Math object to return a numeric value for the angle (theta component) of the polar coordinate (r, theta) that corresponds to the specified Cartesian coordinate (x, y). (If you understood that sentence, congratulations! You’re a rocket scientist.)
Syntax:
Math.atan2(number)
Example:
Math.atan2(90, 15)
back
Use the b а с к () method of the history object to load the previous URL in the history list.
Syntax:
hi story.back()
Example:
hi story.back()
Invoking the back() method of the hi story object produces the same result as hi story. go (-1). Choosing GoOBack from the Navigator or Internet Explorer menu also produces the same result, for that matter. If you know for sure that you only want to go back one URL, the hi story. backO method is the way to go; if you have to calculate how many URLs to go back, hi story, gо () is a better choice.
big
Using the bi g () method of the String object enables you to display a string in big (size 4) font. (To specify font sizes from 1 through 7, see also “f onts i ze”, described later in this part.)
Syntax:
string.big()
Example:
document.write("This is gonna be big!".big())
Previous << 1 .. 29 30 31 32 33 34 < 35 > 36 37 38 39 40 41 .. 72 >> Next