Home  >  Article  >  Web Front-end  >  Detailed explanation of some usages of javascript objects

Detailed explanation of some usages of javascript objects

零下一度
零下一度Original
2017-06-25 09:42:26987browse

This object is not that object. Continuation of the second update. .

Yesterday we talked about the basic concepts and creation of objects. Today we will talk about its other methods:

1. Two ways to access properties: dot syntax and [] syntax

 1 var dog =new Object(); 2 dog.name="阿黄"; 3 dog.age="2"; 4              5 //点语法用来访问对象的属性和方法 6 alert(dog.name); 7              8 //[]语法来访问对象属性 9 alert(dog["name"]);//var a="name";alert(dog[a]);10             11 //dog.name=dog["name"];  他俩是等价的

Both dot syntax and [ ] syntax can access the properties of an object, but there are also differences:

  1. Dot syntax mainly conforms to the variable naming rules;

  2.[ ] syntax can use variables;

  3.[ ] syntax can use invalid js characters; #   4. Dot syntax can be completely replaced with [ ] syntax, but not vice versa;

   5. [ ] syntax can use numbers, keywords, and reserved words to access object properties, but dot syntax cannot.

2. Use

for in

to traverse the object

1 //对象属性的遍历,Key是属性名2     for(var Key in dog){3         console.log(dog[Key]);4         //dog[key]==dog[属性名]5                 //console.log(Key);6     }
3.
delete

Delete attributes

## 4. hasOwnProperty()

This method can be used to detect whether the object has a certain local property, and the return value is TRUE or FALSE

  

 5. instanceof

This method can be used to detect the relationship between instance objects and prototypes.

    

                              

     

                           ute git by . Will update after finishing it!

Loading....

The above is the detailed content of Detailed explanation of some usages of javascript objects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn