Some JavaScript quiz

Source: Internet
Author: User
Tags hasownproperty
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'

 

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.