Common JS creation objects: <br/> var OBJ = new object; </P> <p> obj. name = "Goul"; </P> <p> obj. age = 22; </P> <p> obj. sex = "male"; </P> <p> obj. say = function () {</P> <p> alert ("My name is" + this. name) </P> <p >}; </P> <p> the following uses the <SPAN class = 'wp _ keywordlink '> Program </span> as an example: </P> <p> 1. factory method: </P> <p> function say () {alert ("My name is" + this. name)} // defines the object method outside the factory function, and points to this method through the property </P> <p> function createobj (name, age, sex) {// factory function, three parameters are accepted </P> <p> varobj = new object; </P> <p> obj. name = Name; </P> <p> obj. age = age; </P> <p> obj. sex = sex; </P> <p> obj. say = say; // method pointing out of the factory function </P> <p> return OBJ; // return object </P> <p >}</P> <p> var obj1 = createobj ("Goul", 22, "male "); // create an instance of the class </P> <p> 2. constructor method: </P> <p> function OBJ (name, age, sex) {// constructor </P> <p> This. name = Name; </P> <p> This. age = age; </P> <p> This. sex = sex; </P> <p> This. say = function () {</P> <p> alert ("My name is" + this. name) </P> <p >}</P> <p> var obj1 = new OBJ ("Goul", 22, "male "); // create an instance of the class </P> <p> 3. prototype: </P> <p> function OBJ () {}// define an empty function </P> <p> obj. prototype. name = "Goul"; </P> <p> obj. prototype. age = 22; </P> <p> obj. prototype. sex = "male"; </P> <p> obj. say = function () {</P> <p> alert ("My name is" + this. name) </P> <p >}</P> <p> var obj1 = new OBJ (); // create a class instance </P> <p> 4, constructor: </P> <p> function OBJ (name, age, sex) {// constructor </P> <p> This. name = Name; </P> <p> This. age = age; </P> <p> This. sex = sex; </P> <p >}</P> <p> obj. prototype. say = function () {// method defined in the prototype </P> <p> alert ("My name is" + this. name); </P> <p >}</P> <p> var obj1 = new OBJ ("Goul", 22, "male "); // create an instance of the class </P> <p> 5. Dynamic Prototype Method: </P> <p> function OBJ (name, age, sex) {</P> <p> This. name = Name; </P> <p> This. age = age; </P> <p> This. sex = sex; </P> <p> If (typeof obj. _ initalized = "undefines") {// _ initalize the prefix underline is the private variable that the programmer has achieved </P> <p> obj. prototype. say = function () {</P> <p> alert ("My name is" + this. name) </P> <p >}</P> <p> obj. _ initalized = true; </P> <p >}</P> <p>