ArticleDirectory
- A. X = A ={}, in-depth understanding of the value assignment expression
- Abbreviation of If statement
- & | The calculated value
- Object Construction
- Prototype details
- Create an object and keep the prototype chain
A. X = A ={}, in-depth understanding of the value assignment expression
Code
VaR O = {X: 1 };
VaR A = O;
A. x = A = {Name: 100 };
Console. Log (A. X ); // Undefined
Console. Log (O. X ); // {Name: 100}
// A. X = A = {Name: 100 };
// Equivalent to A. X = (a = {Name: 100 });
// Calculate the reference of A. X, and then calculate the return value of (a = {Name: 100 })
Abbreviation of If statement
VaR Condition = True , Numb = 0 ;
If (Condition ){
Alert ( ' Rain-man ' )
}
If (Condition ){
Numb = 1 + 2 ;
}
Equivalent
VaR Condition = True , Numb = 0 ;
Condition && Alert ( ' Rain-man ' );
Condition && (Numb = 1 + 2 );
& | The calculated value
( True && 222 ); // 222
!! ( True && 222 ); // True
( False && 222 ); // False
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> ( false || 222 ); /// 222
!! ( false || 222 ); /// true
!! Variable returns a Boolean value equal to the original value.
Object Construction
Code
Function Object () {[native code]}
Object. Prototype = {
Constructor: Function Object () {[native code]},
Hasownproperty: Function Hasownproperty () {[native code]},
Isprototypeof: Function Isprototypeof () {[native code]},
Propertyisenumerable: Function Propertyisenumerable () {[native code]},
Tolocalestring: Function Tolocalestring () {[native code]},
Tostring: Function Tostring () {[native code]},
Valueof: Function Valueof () {[native code]}
};
Object. Prototype. Constructor === Object; // True
Prototype details
VaR A = Function (){
This . Name = ' Rain-man ' ;
};
A. Prototype = {
Name: ' Cnblogs '
};
VaR O = New A ();
Console. Log (O. Name ); // 'Rain-man'
Create an object and keep the prototype chain
Code
VaR O = Function (OBJ ){
Function T (){}
T. Prototype = OBJ;
Return New T ();
};
VaR OBJ = {Name: ' OBJ ' , Age: 0 },
Obj1 = O (OBJ ),
Obj2 = O (obj1 );
// Change one location of the prototype chain and all prototype chains will change
OBJ. Name = ' Superclass ' ;
Console. Log (obj1.name ); // 'Superclass'
Console. Log (obj2.name ); // 'Superclass'
// Each layer can be processed separately.
Obj1.name = 100 ;
Console. Log (obj1.name ); // 100
Delete Obj1.name; // Violence and leakage prototype chain
Console. Log (obj1.name ); // 'Superclass'