JavaScript Reference Type Object FAQ example analysis

The example of this article describes the common usage of the JavaScript reference type Object. Share to everyone for reference, specifically:

1, JavaScript data type

(1) Basic type

5 basic types: undefined, null, boolean, number, string

5 reference types: Object, Array, Date, REPEXP, Function

(3) The basic type and the reference type is different:

1) Save mode

The basic type is accessed by value. The value of the reference type is accessed by reference. The value of the reference type is the object saved in the memory. When the JavaScript is actually an operation object, it is actually a reference to the actual object.

2) Copy Variable Value

Copy the basic type value creates a new value on the variable object and then copies the value to the location assigned to the new variable. Copy the reference type value also copies a value of a new variable in the value of the variable object, just a value of a pointer, pointing to an object stored in the heap.

3) Parameter transmission

The access variables in JavaScript have two ways and references, and the parameters can only be passed by value.

2, Object Type

Object is an example of a reference type. Most reference type values ​​are an instance of object types.

— Method of creating an Object instance

(1) uses the

New operator followed by the OBJECT constructor.

VAR PERSON = NewObject (); = “alice”; Person.age = 23; Person.age;

(2) use a literal indication.
   VAR persons = {"name": "Alice", AGE: 23, 5: true}; 

When the property name is a string, quotation marks (single, double quotes) can be used.
The object word is the first choice for transmitting a large number of optional parameters to the function.
  --- Method for accessing object properties  
(1) Point representation

Alert (Person

(2) square brackets

Alert (Person [“Name”];
Advantages of square brackets: access to attributes can be accessed by variables.

Var Property = “Name” If the property name or the like or the attribute name is included in the attribute name, it can only be explicitly represented by square brackets.
 Alert (Person [5]);   
More about JavaScript related content, readers can View this site: “JavaScript is entry for objects”,” JavaScript common function skills “,” JavaScript error and debugging skill summary “,” JavaScript Data Structure and Algorithm Skill Summary “,” JavaScript Page Element Skill Skill Summary “and” JavaScript Operation DOM Skills Summary “

I hope this article will help you JavaScript programming.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment