Basic JavaScript Concepts (II)

Source: Internet
Author: User

The basic concept of an object 1, an object, is an entity in memory, and maintains a certain state for the target object of the programming operation. 2. An object is a collection of names paired with values, also known as attributes. 3. An object can also be defined as a collection of properties. 4. The property value of an object can be specified by a function. 5, with a prototype chain of construction. 6. An object can be used as an associative array for managing key-value pairs. Simple and rude understanding: an entity that a program can use to manipulate data. Second, the object literal expression 1, through the object literal expression to generate an object. 2. Expand with {}. 3, the Internal property name, the property value is composed.
 
   
  
  1. {属性名:属性值,属性名:属性值~~~}
4, the property name can be an identifier, a string, a numeric value. 5, the attribute value can be any value, object
   
 
  1. { x:2,y:1 }//属性名是标识符
  2. { "x":2,"y":1 }//属性名是字符串值
  3. { ‘x‘:2,‘y‘:1 }//属性名是字符串值
  4. { 1:2,2:1 }//属性名是数值
  5. { x:2,y:1, enable:ture,color:{r:255,g:255,b:255} }//属性名是各种类型的属性值
* End as far as possible to avoid using (,) comma end, in the version of older IE browser, this is wrong. However, the last-ending (,) comma is ignored in the 5th version of ECMAScript.
 
    
  
  1. {x:2,y:1,}
6. If you write the object literal on the right side of the assignment expression, you can assign the object's reference to the variable
 
    
  
  1. var obj={x:3,y:4};
  2. document.write(typeof obg);
  3. /*
  4. 输出:
  5. object
  6. */
7. You can access the properties in an object reference by using the operator (.) Dot number. Write the attribute name after the dot number
 
    
  
  1. var ojb={x;3,y:4};
  2. document.write(ojb.x)
  3. /*
  4. 输出:
  5. 3
  6. */
(1), the value of the property is an object, you can read the property through the multiple point operator
 
    
  
  1. var obj={pos:{x:3,y:4}}
  2. document.write(obj.pos.x);
  3. /*
  4. 输出:
  5. 3
  6. */
(2), can overwrite the original property value
 
    
  
  1. var obj={x:3,y:4};
  2. obj.x=33;
  3. document.write(obj.x);
  4. /*
  5. 输出:
  6. 33
  7. */
(3), you can create a new property value
 
    
  
  1. var obj={x:2,y:4};
  2. obj.z=5;
  3. document.write(obj.z);
  4. /*
  5. 输出:
  6. 5
  7. */
8, through the ([]) Bracket for property access (1), the use of ([]) brackets to access the property, inside the parentheses is the need to access the property name of the string value.
 
    
  
  1. var obj={x:3,y:4};
  2. document.write(obj[x]);
  3. /*
  4. 输出:
  5. 3
  6. */
(2), can be a string literal, or it can be a variable with a string literal wolf
 
    
  
  1. var obj={x:3,y:4};
  2. var name=‘x‘;
  3. document.write(obj[name]);
  4. /*
  5. 输出:
  6. 3
  7. */
(3) The parentheses operator can also be used for an assignment expression
 
    
  
  1. var obj={x:3,y:4};
  2. obj[‘5‘]=5;//若不存在则新建一个属性
  3. document.write(obj[5]);
  4. /*
  5. 输出:
  6. 5
  7. */
9, you can assign objects, functions to the properties of the object.
   
 
  1. var obj.fn=function(a,b){
  2. return Number(a)+Number(b);
  3. }
  4. document.write(obj.fn(3,4))
  5. /*
  6. 输出:
  7. 7
  8. */
  9. It's also possible to write.
  10. var sum=function (A, b) {
  11. return number (a) +number (b);
  12. }
  13. var obj.fn=sum;
  14. document.write (Obj.fn (3,4));
  15. /*
  16. Output:
  17. 7
  18. */
10, class and instance (1), JavaScript is the concept of no class, the class is only used to call the implementation of the class function, the function object used to call the constructor.

Reference book information:

1, JavaScript programming full solution http://www.ituring.com.cn/book/1140

2. JavaScript Yu Yingjun Http://pan.baidu.com/s/1eQlegKE



From for notes (Wiz)

Basic JavaScript Concepts (II)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.