Download (direct link):
Methods: Hov) an Object BehaVes
/it this part...
v* Deciding how (and when) to call each method
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.
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:
some bi g text".bi g())
♦ An HTML statement: <BIG>Here is some big
Use the abs () method of the Math object to return the absolute value of a number.
var myResult = Math.abs(l)
Use the acos () method of the Math object to return the arc cosine (in radians) of a number.
var myResult = Math.acos(l)
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.
a 1e rt("message")
alert("Your- order total is " + getOrderTotal())
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.
"Table Of Contents".anchor("T0C_anchor")
<A NAME="TOC_anchor">Table of Contents</A>
Use the a s i n () method of the Math object to return the arc sine (in radians) of a number.
Use the atan () method of the Math object to return the arc tangent (in radians) of a number.
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.)
Use the b а с к () method of the history object to load the previous URL in the history list.
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.
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.)
document.write("This is gonna be big!".big())