Home > front end >  JavaScript object related content
JavaScript object related content

Time:09-21

Development tools and key technology: DW and JavaScript
Author:
He Qia ChinaTime to write: on April 21, 2020,

JavaScript object related content summary
The data type of JS:
String: characters
Number: numerical
Boolean: the Boolean value
Null: Null
Undefined: Undefined
More than 5 kinds of basic data types, as long as it's not more than the 5 kinds of, all for the Object;

If using the basic data types, we can save a person's information
But they are independent of data without contact
For example:
Var name="XiaoNa";
Var age=20;
Var tel="18218685474";
So you can put your data created preserved
Object classification
1. The built-in objects
- by ES standards defined in the object, can be used in any ES the implementation of the
For example: Math String Number Boolean Function Object...

2. The host object
- provided by the operation environment of JS object, is mainly refers to the object provided by the browser
- such as: BOM (browser object model) DOM (document object model (DOM)
For example, we often use the console. The log () is the object in the DOM

3. Custom object
Custom objects are developers themselves defined
For example:
Create objects
Use the new key tone with function, is the constructor constructor
The constructor is specially used to create the object function
Var obj=new Object ();//this is to create objects
The Console. The log (typeif obj)//in the Console through typeif detection data type
Saved in the object value is called attribute
1. To add attributes to the object syntax:
Object. The property name=attribute value (2) the object [" attribute name "]=attribute values
For example:
For the object to add attributes
Var obj=new Object ();//create the object
Obj. Name="XiaoNa";
Obj. Age="20";
Obj. Tel="1821865473";
The Console. The log (obj)
The Console. The log (Obj. Name)//can also directly on the Console query
The Console. The log (Obj/" name ");//the two methods can obtain

- note: if no object attributes, not returned an error but undefined
2. Read the attributes of the object syntax:
(1) the object. The property name (2) the object (" attribute name ")
For example:
For the object to add attributes
Var obj1=new Object ();//create the object
Obj1. [" name "]="XiaoNa";
Obj1. (" age ")="20";
Obj1. [" tel "]="1821865473";
The Console. The log (Obj/" name ");
The Console. The log (Obj. Name);//the two methods can obtain
Modify the object property values
Obj. Name="little dream";//it can be directly modified
Delete the object property values
With the delete code
The delete obj=name;//it can be directly deleted
- note: the above status symbols are in English character, if not, will be an error
  • Related