<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
/*
VaR X;
If (x = NULL ){
Alert ("null ");
}
If (typeof (x) = "undefined "){
Alert ('undefined ');
}
If (! X) {alert ('No x ');}
If (x) {} // The variable is initialized, the variable is not empty, or the variable is not 0.
*/
/*
VaR r = add (1, 2 );
Alert (R );
R = add ("hello", "Tom ");
Alert (R );
Function add (I1, I2 ){
Return I1 + I2;
}
*/
/*
// Anonymous Function
VaR F1 = function (I1, I2 ){
Return I1 + I2;
}
Alert (F1 (1, 2 ));
*/
/*
JS object-oriented BASICS (*)
JavaScript does not have the class syntax. It is simulated using the function closure (closure,
*/
/*
Function person (name, age) {// declare a function as a class
This. Name = Name; // dynamically generate the attribute name
This. Age = age;
This. sayhello = function (){
Alert ("Hello, I am" + this. Name + ", I" + this. Age + "years old ");
}
}
VaR p1 = new person ("Tom", 20 );
// Var p1 = person ("Tom", 20 );
P1.sayhello ();
*/
/*
Array object
The array object in Javascript is an array. First, it is a dynamic array, and
Is a super complex such as arrays in C #, arraylist, and hashtable.
*/
/* Var names = new array ();
Names [0] = "Tom ";
Names [1] = "Jerry ";
Names [2] = "Lily ";
Alert (names. Join ("| "));
Names. Reverse (); // reverse the element in the array
Alert (names );
For (VAR I = 0; I <names. length; I ++ ){
Alert (Names [I]);
}
Alert (getmax (names ));
Function getmax (ARR ){
VaR max = arr [0];
For (VAR I = 0; I <arr. length; I ++ ){
If (max <arr [I]) {
Max = arr [I];
}
}
Return Max;
}
*/
/*
Dictionary in JS
Array in JS is a baby, not only an array, but also a dictionary or a stack.
It is used like hashtable and dictionary, and it is as efficient as they are.
*/
/*
VaR pinyins = new array ();
Pinyins ["persons"] = "Ren ";
Pinyins ["Port"] = "Kou ";
Pinyins ["hand"] = "Shou ";
Alert (pinyins ["persons"]);
Alert (pinyins. persons );
For (var k in pinyins ){
Alert (K + ":" + pinyins. K );
};
*/
// Obtain all the members of an object: the object's members appear in the form of object keys
For (VAR e in document ){
Alert (E );
}
</SCRIPT>
</Body>
</Html>