For a long time to see the online great God's JS code is particularly difficult, the object-oriented way of writing people to see the clouds in the fog. So the study of JS object-oriented, because it is a beginner, will find themselves on the Internet to collate the information, as a memory.
JS Object -oriented 5 methods of writing: (from http://www.iteye.com/topic/434462)
first define the Circle class, which has member variables R, a constant pi, and a member function area () that calculates the areas;
The 1th notation 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 ());
The 2nd way 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));
The 3rd kind of notation var Circle = new Object (); Circle.pi = 3.14159; Circle.area = function (r) { return this. PI * R * r; } Alert (Circle.area (1.0));
The 4th way var circle={ "PI": 3.14159, "area": function (r) { return). PI * R * r; } ; Alert (Circle.area (1.0));
The 5th type is var Circle = new Function ("this"). PI = 3.14159;this.area = function (r) {return r*r*this. PI;} "); Alert ((New Circle ()). Area (1.0));
in the first method to use the Pretotype please see the next section
JS in the Pretotype
A preliminary study on JS object-oriented (top) JS Object-oriented 5 methods of writing