Internet & WWW How to Program Vocabulary 2.2 Connecting to the Internet

Transcription

Internet & WWW How to Program Vocabulary 2.2 Connecting to the Internet
main
Page 1 of 24
Internet & WWW How to Program
Chapter 2 Microsoft Internet Explorer 5.5
Vocabulary
Repositories, aggregate,
2.2 Connecting to the Internet
Bandwidth refers to the amount of data that can be transferred
through a communications medium in a fixed amount of time.
2.4 Searching the Internet
Search engines such as Google, Yahoo Altavista or HotBot store information in data repositories called
database, which allow for quick retrieval of information.
Other sides, such as Microsoft Network, use metasearch engines, which do not maintain database.
Instead, they send the search criteria to other search engines and aggregate the results.
2.7 File Transfer Protocol (FTP)
ftp://
Chapter 3 Photoshop® Elements
Vocabulary
Raster, marquee, lasso, toggling, dithering, interlacing,
Chapter 4 Introduction to XHTML: Part 1
4.3 First XHTML Example
XHTML comments always start with <!-- and end with -->
Titles usually appear in the title bar at the top of the browser window and also as the text identifying a
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 2 of 24
page when users add the page to their list of Favorites or Bookmarks.
Search engines also use the title for cataloging purposes.
4.4 W3C XHTML Validation Service
Validator.w3.org for checking a document’s syntax.
Documents can be validated from either a URL that specifies the location of the file or by uploading a
file to the site Validator.w3.org/file-upload.html.
4.5 Headers
XHTML provides six headers, called header elements. <h1> to <h6>
4.6 Linking
<p><a href = “http://www.deitel.com†>Deitel</a></p>
<a href = “mailto: [email protected]†>[email protected]</a>
4.7 Images
<img src = “xmlhtp.jpgâ€
Program book cover†/>
height = “238â€
width = “183â€
alt = “XML How to
Tip: including the width and height attributes in an <img> tag can result in the browser loading and
rendering pages faster.
Using images as huyperlinks:
<a href = “links.html†><img src = “buttons/link.jpgâ€
“50†alt = “Links Pages†/>
width = “65â€
height =
4.8 Special Characters and More Line Breaks
Using the special character &lt; for the less-than symbol.
www.w3.org/TR/REC-html40/sgml/entities.html
&copy
&amp for &
&frac14 for ?
Sup
Sub
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 3 of 24
< del > for a strike-through text.
<hr />
4.9 Unordered Lists
<ul>
<li>(list item)
4.10 Nested and Ordered Lists
<ol>
<ol type = “I†> or type = “aâ€
Unordered list items may be explicitly set to discs, circles or squares by setting the ul element’s
type attribute to “disc†, “circle†or square†, respectively.
Chapter 5 Introduction to XHTML: Part 2
5.2 Basic XHTML Tables
<table border = “1†width = “40%â€
summary = “This table provides information about the price of fruit†>
Attribute summary dexcribes the table’s contents. This attribute to make the table more accessible
to users with visual impairments.
<caption><strong>Price of Fruit</strong></caption>
The caption element describes the table’s content and helps text based browsers interpret the table
data.
<thead>
<tbody>
<tfoot>
5.3 Intermediate XHTML Tables and Formatting
<colgroup>
<col align = “rightâ€
</colgroup>
span = “1â€
/>
<rowspan>, <colspan>
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 4 of 24
Attribute valign, which aligns data vertically and may be assigned one of four values – “top†,
“middle†, “bottom†or “baseline†which ignores the fonts used for the row data and
sets the bottom of all text in the row on a common baseline.
5.4 Basic XHTML Forms
<form method = “post†action = “/cgi-bin/formmail†>
<p>
<input type = “hidden†name = “recipientâ€
Value = [email protected] />
<input type = “hidden†name = “subjectâ€
Value = “Feedback Form†/>
<input type = “hidden†name = “redirectâ€
Value = “main.html†/>
</p>
<p><label>Name:
<input name = “name†type = “textâ€
Maxlength = “30†/>
</label></p>
size = “25â€
<p>
<input type = “submit†value =
“Submit Your Entries†/>
<input type = “reset†value =
“Clear Your Entries†/>
</p>
</form>
Method = “post†appends form data to the browser request, which contains the protocol (HTTP)
and the requested resource’s URL.
The other possible value, method = “get†appends the form data directly to the end of the URL.
For example, the URL/cgi-bin/formmail might have the form information name = bob appended to it.
The three hidden inputs are: an e-mail address to which the data will be sent, the email’s subject
line and a URL where the browser will be redirected after submitting the form.
5.5 More Complex XHTML Forms
Textarea:
<p><label> Comments: <br />
<textarea name = “comments†rows = “4â€
Enter your comments here.
</textarea>
</label></p>
<input name = “emailâ€
type = “passwordâ€
<label>Site design
<input name = “thingslikedâ€
</label>
cols = “36†>
size = “25â€
type = “checkboxâ€
http://home.earthlink.net/~billyang/main.htm
/>
value = “Designâ€
/>
11/12/2006
main
Page 5 of 24
When your form has several checkboxes with the same name, you must make sure that they have
different values.
Radio buttons are similar to checkboxes, except that only one radio button in a group of radio buttons
may be selected at any time. All radio buttons in a group have the same name attributes and are
distinguished by their different value attributes.
<input name = “howtositeâ€
checked = “checked†/>
type = “radioâ€
value = “search engineâ€
<select name = “rating†>
<option selected = “selected†>Amazing</option>
<option>10</option>
<option>9</option>
:
:
5.6 Internal Linking
<p><a href = “#ceos†>Go to <em>Favorite CEOs</em></a></p>
:
:
<p><a name = “ceos†></a></p>
A hyperlink can specify an internal link in another document by specifying the document name
followed by a pound sign and the named anchor as in:
Href = “page.html#nameâ€
5.7 Creating and Using Image Maps
<map id = “picture†>
<area href = “form.html†shape = “rectâ€
alt = “Go to the feedback form†/>
cords = “2,123,54,143â€
<area shape = “poly†alt = “E-mail the Deitelsâ€
cords = “162,25,154,39,158,54,169,51,183,39,161,26â€
Href = “mailto:[email protected]†/>
<area shape = “circleâ€
</map>
<img src = “deitel.gif†width = “200†height = “144â€
alt = “Deitel logo†usemap = “#picture†/>
5.8 meta Elements
Used for search engines.
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 6 of 24
Two important attributes of the meta element are name and content.
<head>
<meta name = “keywords†content = “web page, design, XHTML, helpâ€
<meta name = “description†content = “This web site will help you learn
the basics of XHTML.†/>
/>
</head>
5.9 frameset Element
<frameset cols = “110, *†>
<frame name = “leftframe†src = “nav.html†/>
<frame name = “main†src = “main.html†/>
<noframes></noframes>
</frameset>
A targe can be set to a number of present values: "_blank" loads the page into a new browser
window. "_self" loads the page into the frame in which the anchor element appears and "_top"
loads the page into the full browser window.
5.10 Nested framesets
<frameset rows = "175, *">
Chapter 6: Cascading Style Sheets (CSS)
6.2 Inline Styles
style
<p style = "font-size: 20pt; color: #0000ff">
6.3 Embedded Style Sheets
in an XHTML document's head section.
<head>
<style type = "text/css">
em {background-color: #8000ff; color: white }
h1 {font-family: arial, sans-serif }
p {font-size: 14pt}
.special {color: blue}
</style>
</head>
<body>
<h1 class = "special">Deitel</h1>
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 7 of 24
</body>
Css rules in embedded style sheets use the same syntax as inline styles: the property name is followed
by a colon(:) and the value of that property. Multiple properties are separated by semilcolons(;).
Relative values -- xx-small, x-small, small, smaller, medium, large, larger, x-large and xx-large.
if a relative font size is specified, such as large or larger, the actual size will be determined by the
browser that displays the font.
6.4 Conflicting Styles
<head>
<style type = "text/css">
a.nodec {text-decoration: none }
a:hover {text-decoration: underline; color: red; background-color: #ccffcc }
li em {color: red; font-weight: bold}
ul ul {text-decoration: underline; margin-left: 15px}
</style>
</head>
Other possible values for text-decoration include blink, overline,line-through and underline.
li, em
{color: red; font-weight: bold}
A plxel is a relative-length measurement--it varies in size, based on screen resolution. Other
relative lengths are em, ex.
To set an element to display text at 150% of its default text size, the author could use the
syntax:
font-size: 1.5em
absolute-length measurements: in(inches, cm(centimeters), mm(millimeters), pt(points; 1pt = 1/72 in)
and pc(picas--1pc = 12pt).
6.5 Linking External Style Sheets
file name: styles.css
another html file:
code:
<head>
<link rel = "stylesheet" type = "text/css" href = "styles.css" />
</head>
6.6 W3C CSS Validation Service
jigsaw.w3.org/css-validator
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 8 of 24
6.7 Positioning Elements
The z-index attribute allows you to layer overlapping elements properly. Elements that have
higher z-index values are displayed in front of elements with lower z-index values.
Code:
<p><img src = "i.gif" style = "position: absolue; top: opx; left: opx; z-index: 1"
alt = "First positioned image" /></p>
<p style = "position: absolute: top: 50px; left: 50px;
z-index: 3; font-size: 20pt;">Positioned Text</p>
Setting the position property to relative, as in class super, lays out the element on the page and
offsets the element by the specified top, bottom, left or right values.
Code:
span {color: red; font-size: .6em; height: 1em}
.super {position: relative; top: -1ex}
.shiftleft {position: relative; left: -1ex}
Element span is a grouping element -- it does not apply any inherent formatting to its contents.
Its primary purpose is to apply CSS rules or id attributes to a block of text. Element span is an
inline-level element -- it is displayed inline with other text and with no line breaks. As similar
element is the div element, which also applies no inherent styles but is displayed on its own
line, with margins above and below (a block-level element).
6.8 Backgrounds
Code:
<style type = "text/css">
body { background-image: url(logo.gif);
background-position: bottom right;
background-repeat: no-repeat; background-attachment: fixed; }
p
{ text-indent: 1em; font-family: arial, sans-serif; }
.dark { font-weight: bold; }
</style>
<body>
<P>
This example uses <span class = "dark">Deitel ...</span>logo in ....
</p>
</body>
The background-image
The background-position property controls the image on the page. The keywords top,
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 9 of 24
bottom, center, left and right are used individually or in combination for vertical and
horizontal positioning.
Positioned at 50% of the distance across the screen) and 30 pixels from the top, use
background-position: 50% 30px;
The background-repeat property can be set to repeat (the default) to tile the image vertically
and horizontally, repeat-x to tile the image only horizontally or repeat-y to tile the image only
vertically.
The background-attachment: fixed, fixes the image in the position specified by
background-position. Scolling the browser window will not move the image from its position.
The default value, scroll , moves the image as the user scrolls through the document.
6.9 Element Dimensions
div { background-color: #ffccff; margin-bottom: .5em }
<div style = "width: 80%; height: 30%; overflow: scroll; text-align: center">
6.10 Text Flow and the Box Model
div = "float: right; margin: .5em; text-align: right">
div = "float: right; padding; .5am; text-align: right">
The margin specifies the distance between the edge of the element and any other element on
the page. When the browser renders elements using the box model, the content of each element
is surrounded by padding, a border and a margin.
Margins for individual sides of an element can be specified by using margin-top, marginright, margin-left and margin-bottom.
Padding is the distance between the content inside an element and the element's border. Like
the margin, the padding can be set for each side of the box, with padding-top, padding-right,
padding-left and padding-bottom.
You can interrupt the flow of text around a floaed element by setting the clear property to the
same direction as that in which the element is floated -- right or left. Setting the clear property
to all interrupts the flow on both sides of the document.
<span style = "clear: right">
Other style:
This text has a border
This text has a border
This text has a border
A thin red line...
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 10 of 24
And a thicker blue line
In this example, we set three properties -- border-width, border-color and border-style. The
border-width property may be set to any of the CSS lengths or to the predefined values of
thin, medium or thick. The border-color property sets the color.
As with padding and margins, each of the border properties may be set for individual sides of
the box (e.g., border-top-style or border-left-color).
The border-styles are none, hidden, dotted, dashed, solid, double, groove, ridge, inset and
outset. Borders groove and ridge have opposite effects, as do inset and outset.
6.11 User Style Sheets
relative measurements: em or ex
absolue measurements such as pt
Chapter 7 JavaScript: Introduction to Scripting
Vocabulary
carriage return, magenta, facilitates, arithmetic
7.2 Simple Program: Printing a Line of Text in a Web Page
<head>
<script type = "text/javascript">
<!-document.writeln(
"<h1>Welcome to JavaScript Programming!</h1>" );
// -->
</script>
</head>
See the web
JavaScript is case sensitive.
write
writeln: after a writeln statement, the next output appears on the next line.
The backslash (/) in a string is an escape character. We use this escape sequence to insert
double quotes around the attribute value for style.
document.write( "<h1 style = \"color; magenta\">" );
document.write( "Welcome to Java Script " +
"Programming!</h1>" );
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 11 of 24
See the web
window.alert ("Welcome to \nJavaScript\nProgramming!" );
See the web
\n
\t
\r
\\
\"
\'
7.3 Another JavaScript Program: Adding Integers
The script uses anotehr predefined dialog box from the window object, one called a prompt
dialog. that allows the user to input a value form use in the script.
var firstNumber,
secondNumber,
number1,
number2,
sum;
firstNumber = window.prompt( "Enter first integer", "0" );
secondNumber = window.prompt( "Enter second integer", "0" );
number1 = parseInt (firstNumber);
number2 = parseInt (secondNumber);
sum = number1 + number2;
document.writeln ("<h1>The sum is " + sum + "</h1>" );
Show the example
Some valid identifiers are Welcome, $value, _value, m_inputField1 and button7. The name
7button is not a valid identifier, because it begins with a digit, and the name input field is not
a valid identifier, because it contains a space.
Another comment notation facilitates the writing of multiple_line comments. For example,
/* This is a multiple-line
comment */
7.6 Decision Making: Equality and Relational Operators
var first,
second,
number1,
number2;
first = window.prompt("Enter first integer:", "0");
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 12 of 24
second = window.prompt("Enter second integer:","0");
number1 = parseInt(first);
number2 = parseInt(second);
document.writeln("<h1>Comparison Results</h1>");
document.writeln(
"<table border=\"1\" width = \"100%\" ID="Table1">");
if (number1 == number2)
document.writeln("<tr><td>" + number1 + " == " +
number2 + "</td></tr>");
if (number1 != number2)
document.writeln("<tr><td>" + number1 + " != " +
number2 + "</td></tr>");
if (number1 < number2)
document.writeln("<tr><td>" + number1 + " < " +
number2 + "</td></tr>");
if (number1 > number2)
document.writeln("<tr><td>" + number1 + " > " +
number2 + "</td></tr>");
if (number1 <= number2)
document.writeln("<tr><td>" + number1 + " < = " +
number2 + "</td></tr>");
if (number1 >= number2)
document.writeln("<tr><td>" + number1 + " > = " +
number2 + "</td></tr>");
document.writeln("</table>");
Show the example
7.7 JavaScript Internet and World Wide Web Resources
Some resources for JavaScript programming:
www.ecma.ch/ecma1/stand/ecma-262.htm
msdn.microsoft.com/scripting/default.htm
www.webteacher.com/javascript
Chapter 8 JavaScript: Control Structures I
Vocabulary
pajamas, sentinel,
8.6 if/else Selection Structure
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 13 of 24
JavaScript provides an operator, call the conditional operator (?:), that is closely related to the
if/else structure.
document.writeln (
studentGrade >= 60 ? "Passed" : "Failed" );
8.8 Formulating Algorithms:
Case Study1 (Counter-Controlled Repetition)
a class of ten students took a quiz. The grades (integers in the range 0 to 100) for this quiz are
available to you. Determine the class average on the quiz.
<script type="text/javascript">
<!-var total,
gradeCounter,
gradeValue,
average,
grade;
total = 0;
gradeCounter = 1;
while (gradeCounter <= 10) {
grade = window.prompt("Enter integer grade:"+
"(number " + gradeCounter + ")", "0" );
gradeValue = parseInt( grade );
total = total + gradeValue;
gradeCounter = gradeCounter + 1;
}
average = total / 10;
document.writeln(
"<h1>Class average is " + average + "</h1>" );
//-->
</script>
Show the example
8.9 Formulating Algorithms with Top-Down, Stepwise
Refinement: Case Study 2 (sentinel-Controlled Repetition)
Develop a class-averaging program that will process an arbitrary number of grades each time
the program is run.
<script type="text/javascript">
<!-var total,
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 14 of 24
gradeCounter,
gradeValue,
average,
grade;
total = 0;
gradeCounter = 0;
grade = window.prompt("Enter integer grade "+
"(number " + gradeCounter + "):", "0" );
gradeValue = parseInt( grade );
while (gradeCounter <= 10) {
total = total + gradeValue;
gradeCounter = gradeCounter + 1;
grade = window.prompt("Enter integer grade:"+
"(number " + gradeCounter + ")", "0" );
gradeValue = parseInt( grade );
}
if (gradeCounter != 0) {
average = total / gradeCounter;
document.writeln(
"<h1>Class average is " + average + "</h1>" );
}
else
document.writeln( "<p>No grades were entered</p>" );
//-->
</script>
Show the example
8.10 Formulating Algorithms with Top-Down, Stepwise
Refinement: Case Study 3 (Nested Control Structures)
<script type="text/javascript">
<!-var passes = 0,
failures = 0,
student = 1,
result;
while (student < =10) {
result = window.prompt(
"Enter result (1=pass, 2=fail)", "0");
if (result == "1")
passes = passes +1;
else
failures = failures +1;
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 15 of 24
student = student +1;
}
document.writeln("<h1>Examination Results</h1>");
document.writeln(
"Passed: " + passes + "<br />Failed: " + failures );
if (passes > 8)
document.writeln( "
Raise Tuition" );
//-->
</script>
8.12 Increment and Decrement Operators
var c;
c=5
document.writeln ("<h3>Postincrementing</h3>" );
document.writeln (c);
//print 5
document.writeln(c++); //print 5
document.writeln(c);
//print 6
c=5
document.writeln ("<h3>Preincrementing</h3>" );
document.writeln (c);
//print 5
document.writeln(++c);
//print 6
document.writeln(c);
//print 6
8.14 JavaScript Internet and World Wide Web Resources
Some resources for JavaScript programming:
www.javascriptmall.com
developer.netscape.com/tech/javascript
Chapter 9 JavaScript: Control Structures II
Vocabulary
oracle, alter,
9.4 Examples Using the for Structure
var amount, deposit, interest, principal, rate;
deposit = window.prompt("Deposit amount: " , "1000");
interest = window.prompt("interest is: (as 0.05)", "0.05");
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 16 of 24
principal = parseInt(deposit);
rate = parseFloat(interest);
document.writeln(
"<table border = \"1\" width = \"100%\" ID="Table1">");
document.writeln(
"<caption>Calculating Compound Interest</caption>");
document.writeln(
"<thead><tr><th align = \"left\">Year</th>" );
document.writeln(
"<th align = \"left\">Amount on deposit</th>");
document.writeln(
"</tr></thead>");
for (var year=1; year<=10; ++year) {
amount= principal * Math.pow(1.0+rate,year);
document.writeln("<tbody><tr><td>" + year +
"</td><td>" + Math.round(amount*100)/100 +
"</td></tr>");
}
document.writeln("</tbody></table>");
Show the example
9.5 switch Multiple-Selection Structure
<script type = "text/javascript">
<!-var choice,
startTag,
endTag,
validInput = true,
listType;
choice = window.prompt( "Select a list style:\n" +
"1(bullet), 2(numbered, 3(lettered)", "1");
switch (choice) {
case "1":
startTag = "<ul>";
endTag = "</ul>";
listType = "<h1>Bullet List</h1>";
break;
case "2":
startTag = "<ol>";
endTag = "</ol>";
listType = "<h1>Ordered List: Numbered</h1>";
break;
case "3":
startTag = "<ol type = \"A\">";
endTag = "</ol>";
listType = "<h1>Ordered List: Lettered</h1>";
break;
default:
validInput = false;
}
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 17 of 24
if (validInput == true) {
document.writeln(listType + startTag);
for (var i = 1; i<=3; ++i)
document.writeln("<li>List item " + i + "</li>");
document.writeln(endTag);
}
else
document.writeln("Invalid choice: " + choice );
// -->
</script>
Show the example
9.7 break and continue Statements
for (var count = 1; count <= 10; ++count ) {
if (count == 5)
continue; //skip remaining code in loop only if count == 5
document.writeln ("Count is: " + count + "<br />" );
the resoult will be:
Count is: 1
Count is: 2
Count is: 3
Count is: 4
Count is: 6
Count is: 7
Count is: 8
Count is: 9
Count is: 10
9.8 Labeled break and continue Statements
stop: {
for (...){
for (...){
if (...)
break stop; // jump to end of stop block
document.write("*");
}
}
}
document.writeln("End of script");
nextRow: {
for (...){
for (...){
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 18 of 24
if (...)
continue nextRow; // next iteration of labeled loop
document.write("*");
}
}
}
document.writeln("End of script");
Chapter 10 JavaScript: JavaScript: Functions
Vocabulary
,
10.4 Function Definitions
The format of a function definition is
function function-name( parameter-list )
{
declarations and statements
}
Example:
function square( y )
{
return y * y;
}
function maximum (x, y, z)
{
return Math.max(x, Math.max( y, z ));
}
10.5 Random-Number Generation
0.0 <= Math.radom() < 1.0
value = Math.floor( 1 + Math.random() * 6 );
10.6 Example: Game of Chance
A player rolls two dice. Each die has six faces. These faces contain 1,2,3,4,5 and 6 spots,
respectively. After the dice have come to rest, the sum of the spots on the two upward faces is
calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3 or 12 on
the first throw (called "craps"), the player loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8,
9 or 10 on the first throw, that sum becomes the player's "point". To win, you must continue
rolling the dice until you "make your point" (i.e., roll your point value). The player loses by
rolling a 7 before making the point.
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 19 of 24
Show the example
10.8 Scope Rules
Ientifiers declared inside a function have function (or local scope.
Show the example
10.9 JavaScript Global Functions
escape, eval, isFinite, isNaN, ParseFloat, ParseInt, unescape
10.10 Recursion
Show the example
10.11 Example Using Recursion: Fibonacci Series
Show the example
10.12 Recursion vs. Iteration
Both iteration and recursion can occur infinitely.
Recursion has many negatives. Being expensive in terms of both processor time and memory
space.
10.13 JavaScript Internet and World Wide Web Resources
rummelplatz.uni-mannheim.de/~skoch/js/tutorial.htm
www.stars.com/Authoring/JavaScript/Tutorial/functions.html
www.w3schools.com/js/js_functions.asp
Chapter 11 JavaScript: Arrays
Vocabulary
,
11.2 Arrays
if we assume that variable a is equal to 5 and that variable b is equal to 6 , then the statement
c[a + b] += 2;
adds 2 to array element c[11].
The length of array c is 12 ans is determined by the following expression:
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 20 of 24
c.length
11.3 Declaring and Allocating Arrays
To allocate 12 elements for integer array c , use the statement
var c = new Array( 12 );
11.4 Examples Using Arrays
There are two ways in which the initial values can be specified.
var n = [10, 20, 30, 40, 50];
or
var n = new Array(10, 20, 30, 40, 50);
var colors = new Array( "cyan", "magenta", "yellow", "black" );
11.5 References and Reference Parameters
Two ways to pass arguments to functions (or methods) in many programming languages are
call-by-value and call-by-reference .
Passing arrays by reference make sense for performance reasons.
11.6 Passing Arrays to Functions
For example:
var hourlyTemperatures = new Array ( 24 );
then the function call
modifyarray ( hourlyTemperatures );
In JavaScript, every array object "knows" its own size (via the length attribute). Thus, when
we pass an array object into a function, we do not pass the size of the array separately as an
argument.
Array method join creates a string containing all the elements in the Array. Method join takes
as its argument a string containing the separator that should be used to separate the elements of
the array in the string that is returned. If the argument is not specified, the empty string is used
as the separator.
function start()
{
var a = [ 1, 2, 3, 4, 5 ];
document.writeln( “<h2>Effects of passing entire “ +
“array call-by-reference</h2>â€
);
outputArray(
“The values of the original array are: “, a );
modifyArray( a );
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 21 of 24
outputArray (
“The values of the modified array are: “, a );
//the above function call will modify the array
document.writeln( “<h2>Effects of passing array “ +
“element call-by-value</h2>â€
+
“a[3] before modifyElement: “ + a[3] );
modifyElement ( a[ 3 ] );
document.writeln(
“<br />a[3] after modifyElement: “ + a[3] );
//the value doesn't change.
}
function outputArray( header, theArray )
{
document.writeln(
header + theArray.join( “ “ ) + “<br />â€
);
}
function modifyArray( theArray )
{
for ( var j in theArray )
theArray[ j ] *= 2;
}
function modifyElement( e )
{
e *= 2;
document.writeln( “<br />value in modifyElement: “ + e );
}
theArray.join( " " )
for ( var j in theArray )
theArray[ j ] *= 2;
11.7 Sorting Arrays
var a = [ 10, 1, 8, 8, 3, 5, 4 ]
a.sort( compareIntegers ); //sort is a built-in method
function compareIntegers ( value1, value2 )
{
return parseInt( value1 ) - parseInt( value2 );
//it's in ascending order.
}
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 22 of 24
11.8 Searching Arrays: Linear Search and Binary Search
11.9 Multiple-Subscripted Arrays
var b = [ [ 1, 2 ], [ 3, 4 ] ];
A multiple-subscripted array in which each row has a different number of columns can be
allocated dynamically as follows:
var b;
b = new Array ( 2 );
b[ 0 ] = new Array( 5 );
b[ 1 ] = new Array( 3 );
var total = 0;
for ( var row in a )
for ( var col in a [ row ] )
total += a[ row ][ col ];
Appendix G
Unicode
Vocabulary
Consortium, glyphs, misrepresentation, adaptation, cumbersome, facilitate, envision,
unambiguous, encompass, hexadecimal, predominance, surrogate, alphabetic, numerals,
punctuation, ideographs, syllabaries, diacritics, tilde, disparate, hindrance, linguistics,
Armenian, Kannada, exclamation mark, Hiragana,
Website: www.unicode.org
UTF-8 data consists of 8-bit bytes (sequences of one, two three or four bytes depending on the
character being encoded) and is well suited for ASCII-base systems when there is a
predominance of one-byte characters (ASCII represents characters as one-byte)
UTF-8 is a variable width encoding form that is more compact for text involving mostly Latin
characters and ASCII punctuation.
UTF-16 is the default encoding form of the Unicode Standard. It is a variable width encoding
form that uses 16-bit code units instead of bytes. Most characters are represented by a single
unit, but some characters require surrogate pairs.
UTF-32 is a 32-bit encoding form. The major advantage of the fixed-width encoding form is
that it uniformly expresses all characters, so that they are easy to handle in arrays and so forth.
Index
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 23 of 24
C
CGI: Common Gateway Interface
CSS: Cascading Style Sheets
D
DBCS: double-byte character set
DSL: digital subscriber line
H
HTTP: hypertext transfer protocol
I
ICW: internet connection wizard
ISDN: Integrated Services Digital Network
J
JPEG: Joint Photographic Experts Group
M
MBCS: multi-byte character set
P
PDF: portable document format
PNG: Portable Network Graphics
T
TA: terminal adaptor
U
URL: Uniform Resource Locator
UTFP: Unicode transformation formats
X
XHTML: Extensible Hypertext Markup Language
http://home.earthlink.net/~billyang/main.htm
11/12/2006
main
Page 24 of 24
2005 TOPYANG版權所有。 ä¿ ç•™æ‰€æœ‰æ¬Šåˆ©
http://home.earthlink.net/~billyang/main.htm
11/12/2006