Define the Circle class, member function area () with member variable r, constant pi, and calculated areas
// The 1th kind of notation function Circle (r) { this.r =3.14159= function () { return This This . R;} var New Circle (1.0);
// 2nd notation Circle = function () { var obj = Span style= "color: #0000ff;" >new Object (); Obj. PI = 3.14159 ; Obj.area = function (r) { return Span style= "color: #0000ff;" >this . PI * r * R; return obj;} var C = new Circle (); Alert (C.area ( 1.0 ));
// 3rd notation Circle = new Object (); Circle.pi = 3.14159 ; Circle.area = function (r) { return this . PI * r * R;} Alert (Circle.area ( 1.0 ));
// 4th notation circle={ " pi : 3.14159 , area " :function (R) { return this . PI * r * R; }};alert (Circle.area ( 1.0 ));
// The 5th kind of notation var New Function ("this. PI = 3.14159;this.area = function (r) {return r*r*this. PI;} " ); alert ((new Circle ()). Area (1.0));
JS Object-oriented 5 notation