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

Source: Internet
Author: User

I. Functions

Definition:

 
Function Square (x) {return x * x}

Ii. object,Set of named Data

1. Create

 
VaR o = new object (); var now = new date (); var pattern = new Regexp ("\ sjava \ s", "I ");

2. Call attributes

 
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.

 
VaR point = {X: 2.3, Y:-1.2 };

4. Objects can also be nested

 
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.

 
Document. Images [1]. Width

2. Create an array using the constructor array ()

 
VaR A = new array (); A [0] = 1.2; A [1] = "bingzong"; A [2] = true; A [3] = {X: 1, Y: 3} // create an array var A = new array (1.2, "Mr. sao ", true); // only one parameter is passed. The specified parameter is the array length var A = new array (10 ); // You can also use the syntax var A = [1.2, "mr. Sao", true] // You can also store undefined elements var A = [1, 5]

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.