[JavaScript] Some prototype descriptions

Source: Internet
Author: User
  VaR  Point  =     Function  (X, y ){
This . X = X;
This . Y = Y;
}
Point. Name = ' I am name ' ;
Point. Prototype. Sum = Function (){
Return This . X + This . Y;
}
Point. Prototype. Odd = Function (){
Alert ( This . Sum ());
}
VaR A = New Point ( 1 , 2 );
A. Odd (); VaR B = New Point ( 3 , 4 );
B. Odd ();

Point. Prototype = { // This process will overwrite the previous method (sum, odd)
Plus: Function (){
Return This . X - This . Y;
},
Odd2: Function (){
Alert ( This . Plus ());
}
}
B. Odd (); // There will be no exception here
VaR C = New Point ( 5 , 3 );
C. odd2 (); // There will be no exception here
Alert (C. Name ); // Exception undefined can draw a conclusion point. Name! = Point. Prototype. Name
// Point. Prototype. Name is used after instantiation, and point. Name is equivalent to its own static variable.
C. Odd (); // An exception occurs here.

1. prototype: the attributes added by prototype are the same as those of the instantiated functions (attributes). If it is point. Sum, sum cannot be called in new point.

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.