Java code
Copy codeThe Code is as follows:
// 1st writing methods
Function Circle (r ){
This. r = r;
}
Circle. PI = 3.14159;
Circle. prototype. area = function (){
Return Circle. PI * this. r * this. r;
}
Var c = new Circle (1.0 );
Alert (c. area ());
Java code
Copy codeThe Code is as follows:
// 2nd writing methods
Var Circle = function (){
Var obj = new Object ();
Obj. PI = 3.14159;
Obj. area = function (r ){
Return this. PI * r;
}
Return obj;
}
Var c = new Circle ();
Alert (c. area (1.0 ));
Java code
Copy codeThe Code is as follows:
// 3rd writing methods
Var Circle = new Object ();
Circle. PI = 3.14159;
Circle. Area = function (r ){
Return this. PI * r;
}
Alert (Circle. Area (1.0 ));
Java code
Copy codeThe Code is as follows:
// 4th writing methods
Var Circle = {
"PI": 3.14159,
"Area": function (r ){
Return this. PI * r;
}
};
Alert (Circle. area (1.0 ));
Java code
Copy codeThe Code is as follows:
// 5th writing methods
Var Circle = new Function ("this. PI = 3.14159; this. area = function (r) {return r * this. PI ;}");
Alert (new Circle (). area (1.0 ));
Let's discuss the advantages and disadvantages of these five writing methods. Which of them is more standard, especially the last two.