(3) JavaScript learning notes-functions, objects, Arrays

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.