I. Functions
Definition:
[Javascript]
Function square (x)
{
Return x * x
}
Ii. Object: a set of named Data
1. Create
[Javascript]
Var o = new object ();
Var now = new date ();
Var pattern = new RegExp ("\ sjava \ s", "I ");
2. Call attributes
[Javascript]
Var poit = new object ();
Point. x = 2.3;
Point. y =-1.2;
3. object initialization. The object direct quantity is composed of a list, which is an attribute/value pair separated by colons.
[Javascript]
Var point = {x: 2.3, y:-1.2 };
4. Objects can also be nested
[Javascript]
Var rectangle = {upperLeft: {x: 2, y: 2 };
LowerRight: {x: 2, y: 4}
}
5. the attribute value in the object does not need to be a constant, but can be any expression. The attribute name can be a string rather than an identifier.
3. Array
1. Arrays can store any JS data type.
[Javascript]
Document. images [1]. width
2. Create an Array using the constructor Array ()
[Javascript]
Var a = new Array ();
A [0] = 1.2;
A [1] = "BingZong ";
A [2] = true;
A [3] = {x: 1, y: 3}
// Create an array by passing an array element
Var a = new Array (1.2, "Mr. Sao", true );
// Only one parameter is passed, which specifies the length of the array.
Var a = new Array (10 );
// You can also use the syntax for creating and initializing the direct quantity of arrays.
Var a = [<span style = "background-color: rgb (255,255,255);"> 1.2, "Mr. Sao", true </span>]
// You can also store undefined elements.
Var a = [1, 5]
By: dxh_0829