Basic Javascript tutorials-basic knowledge of function objects and attributes-js tutorials

Source: Internet
Author: User
This article mainly introduces the function objects and attributes in the basic Javascript tutorial. You can refer to the data contained in objects to access them in two ways.

BothProperty and method)

A property is a variable belonging to a specific object, and a method is a function that can be called by a specific object.

Objects are accessed by attributes and methods in a data entity and javacript that are composed of related attributes and methods.

The Code is as follows:


Object. proprty
Object. method ()

Assume that a Car has a brand band and a color attribute. You can use the following methods to access these attributes:

The Code is as follows:


Car. band
Car. color

Assume that the Car is associated with functions such as move (), stop (), and addOil. These functions are the methods of Car objects.

The Code is as follows:


Car. move ()
Car. stop ()
Car. addOil ()

These attributes and methods are combined to form a Car object. In other words, you can regard the Car object as a general term for all these attributes and methods.

To enable a Car object to describe a specific Car, you need to create an instance of the Car object. The instance is the specific manifestation of the object. Objects are collectively referred to as instances.

For example, cars can be used to describe BMW xiali cars. A bmw and a xiali are different heads. They are Car objects, but different instances.

In javascript, The new Keyword is used to create a new instance. As follows:

Var myCar = new Car ();
The above Code creates a new instance myCar of a Car object. With this instance, you can use the attributes and methods of the Car object to retrieve the attributes and methods of myCar. The Code is as follows:

The Code is as follows:


MyCar. band
MyCar. addOil ()

In javascript, strings and arrays are all objects. Strictly speaking, everything is an object.

The Code is as follows:


Var aValues = new Array ();
Var myString = new String ("hello world ")

Use the Date object to test the computer's execution speed

The Code is as follows:


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.