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.
{属性名:属性值,属性名:属性值~~~}
4, the property name can be an identifier, a string, a numeric value. 5, the attribute value can be any value, object
{ x:2,y:1 }//属性名是标识符
{ "x":2,"y":1 }//属性名是字符串值
{ ‘x‘:2,‘y‘:1 }//属性名是字符串值
{ 1:2,2:1 }//属性名是数值
{ 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.
{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
var obj={x:3,y:4};
document.write(typeof obg);
/*
输出:
object
*/
7. You can access the properties in an object reference by using the operator (.) Dot number. Write the attribute name after the dot number
var ojb={x;3,y:4};
document.write(ojb.x)
/*
输出:
3
*/
(1), the value of the property is an object, you can read the property through the multiple point operator
var obj={pos:{x:3,y:4}}
document.write(obj.pos.x);
/*
输出:
3
*/
(2), can overwrite the original property value
var obj={x:3,y:4};
obj.x=33;
document.write(obj.x);
/*
输出:
33
*/
(3), you can create a new property value
var obj={x:2,y:4};
obj.z=5;
document.write(obj.z);
/*
输出:
5
*/
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.
var obj={x:3,y:4};
document.write(obj[x]);
/*
输出:
3
*/
(2), can be a string literal, or it can be a variable with a string literal wolf
var obj={x:3,y:4};
var name=‘x‘;
document.write(obj[name]);
/*
输出:
3
*/
(3) The parentheses operator can also be used for an assignment expression
var obj={x:3,y:4};
obj[‘5‘]=5;//若不存在则新建一个属性
document.write(obj[5]);
/*
输出:
5
*/
9, you can assign objects, functions to the properties of the object.
var obj.fn=function(a,b){
return Number(a)+Number(b);
}
document.write(obj.fn(3,4))
/*
输出:
7
*/
- It's also possible to write.
- var sum=function (A, b) {
- return number (a) +number (b);
- }
- var obj.fn=sum;
- document.write (Obj.fn (3,4));
- /*
- Output:
- 7
- */
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)