Java code
Copy Code code as follows:
The 1th Way of writing
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 Code code as follows:
The 2nd Way of writing
var Circle = function () {
var obj = new Object ();
Obj. PI = 3.14159;
Obj.area = function (r) {
return this. PI * R * r;
}
return obj;
}
var c = new Circle ();
Alert (C.area (1.0));
Java code
Copy Code code as follows:
The 3rd Way of writing
var Circle = new Object ();
Circle.pi = 3.14159;
Circle.area = function (r) {
return this. PI * R * r;
}
Alert (Circle.area (1.0));
Java code
Copy Code code as follows:
The 4th Way of writing
var circle={
"PI": 3.14159,
' Area ': function (r) {
return this. PI * R * r;
}
};
Alert (Circle.area (1.0));
Java code
Copy Code code as follows:
The 5th Way of writing
var Circle = new Function ("this. PI = 3.14159;this.area = function (r) {return r*r*this. PI;} ");
Alert ((New Circle ()). Area (1.0));
Let's talk about these five kinds of writing, their advantages and disadvantages, which comparison norms, especially the last two, often seen.