The data contained in the object can be accessed in two ways
Objects and methods of properties
An attribute is a variable affiliated to a specific object, and a method is a function that can only be transferred by a specific object.
An object is a data entity that is collected by some related properties and methods in JavaScript. The properties and methods are accessed using the syntax of "points".
The code copy is as follows:
Object.proprty
Object.method()
Assuming a car has a branded band, color attribute, you can access these attributes through the following methods.
The code copy is as follows:
Car.band
Car.color
Suppose Car is associated with some functions such as move(), stop(), and addOil. These functions are the methods of Car's object. You can use the following method to transfer it.
The code copy is as follows:
Car.move()
Car.stop()
Car.addOil()
These properties and methods are collected together to form a Car object. In other words, the Car object can be regarded as a general term for all these properties and methods.
In order for a Car object to describe a specific car, it is necessary to create an instance of the Car object, which is a specific representation of the object. Objects are collective names, instances are individuals.
For example, BMW and Shaley are all cars, and they can be described as Car. A BMW and a Charlie are both of different sizes. They are both Car objects, but different instances.
In javascript, create new instances with the new keyword. as follows
var myCar = new Car();
The above code creates a new instance of the Car object myCar. With this instance, you can use the properties and methods of the Car object to retrieve the properties and methods of the myCar. The code is as follows
The code copy is as follows:
myCar.band
myCar.addOil()
In javascript, strings and arrays are objects. Strictly speaking, everything is objects
The code copy is as follows:
var aValues = new Array();
var myString = new String("hello world")
Test the execution speed of the computer with the Date object
The code copy is as follows:
<script type="text/javascript">
var Date1 = new Date();
for (var i =0 ;i<3000000;i++);
var Date2 = new Date();
document.write(Date2 - Date1);
</script>