HTML and CSS Reference
In-Depth Information
EXPLANATION
1
The ucLarge() function is defined. Its purpose is to generate and return an upper-
case, bold, white font, with a point size of 22.
2
The prototype property allows you to customize an object by adding new proper-
ties and methods. The name of the customized method is ucLarge , which is the
name of a new method that will be used by the String object. It is assigned the
name (without parentheses) of the function ucLarge() , which performs the meth-
od's actions and returns a value. Using the same name for both the property and
the function reduces the chance of mistakenly calling the method by the wrong
name.
3
A new string is created.
4
The prototyped method, ucLarge() , is applied to the String object, str . It will mod-
ify the string as shown in the output in Figure 9.29.
Figure 9.29 Using the String object's prototype property.
String Methods. There are two types of string methods: the string formatting meth-
ods that mimic the HTML tags they are named for, and the methods used to manipulate
a string such as finding a position in a string, replacing a string with another string, mak-
ing a string uppercase or lowercase, and the like.
Table 9.9 lists methods that will affect the appearance of a String object by applying
HTML tags to the string, for example, to change its font size, font type, and color. Using
these methods is a convenient way to change the style of a string in a JavaScript program,
much easier than using quoted HTML opening and closing tags.
Table 9.9 String Object (HTML) Methods
Method
Formats as HTML
String.anchor(Name)
<a name="Name">String</a>
String.big()
<big>String</big>
String.blink()
<blink>String</blink>
Continues
 
Search WWH ::




Custom Search