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: