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.