<! DOCTYPE html>window.onload=function(){//1********************************************************************************************************** ****//var box=new Object ();//1: Basic method for creating a function//box.name= "Feige";//box.run=function () {//alert (this.name+ "Runnig ...")// }// //Box.run ();////Disadvantage is that if you want to create a similar object to generate a lot of code //2 Factory mode ***************************************************************************************************** *********// //function Createobj (name,age) {//co-production mode creation Object//var obj=new Object ();//Obj.name=name;//Obj.age=age;//obj.run=function () {//alert (this.name+this.age+ "Running ...");// }// //return obj;//returns Object reference// // }//function CreateObj2 (name,age) {//co-production mode creation Object//var obj=new Object ();//Obj.name=name;//Obj.age=age;//obj.run=function () {//alert (this.name+this.age+ "Running ...");// }// //return obj;//returns Object reference// // }//var box1=createobj (' Feige ', 22);//Create first object//var box2=createobj (' cc ', 22);//Create a second object//Box1.run ();//Box2.run ();//var box3=createobj2 (' KKK ', 2);// ////ps: Although the factory model solves the problem of repeated instantiation, it is impossible to figure out which of them is an instance of the object, such as the following//alert (box1 instanceof Object);//true//alert (box3 instanceof Object);//still true// // //3 Construction Method Creation Object ************************************************************************************************** ************functionBox (name,age) {//Construction Method Creation Object (modified factory method) This. name=name; This. age=Age ; This. run=function() {alert ( This. name+ This. age);}}functionBox2 (name,age) {//constructing methods to create objects This. name=name; This. age=Age ; This. run=function() {alert ( This. name+ This. age);}}varbox1=NewBox (' CC ', 13);//instantiation ofvarBox2=NewBox2 (' cc ', 21);//instantiation of//alert (box1 instanceof Box);//alert (box2 instanceof Box);//differs from Factory mode to distinguish instance, Box2 is a reference to Box2 object//1. The constructor does not have a new object but the background will automatically var obj=new object ();//2.this is the equivalent of obj//3. The constructor does not need to return an object reference, he is automatically returned by the background//Specification//1. The constructor is also a function, but the first letter of the function name is capitalized//2. Must new constructor (), New Box ()//3. You must use the new operatorvaro=NewObject ();//object posing, you can take the entire constructor down to the OBox.call (O, "posing", 12) O.run ();}</script></body> How JavaScript creates objects