Person class
varperson ={making:function(name,age) { This. Name =name; This. Age =Age ; }, say:function() {document.write ( This. name+ "" + This. age+ ""); }}//Create the object's function, you need to pass two parameters, one is class (person), and one is the argument of the class. functionCreate (obj,arg) {functionCreate_inter () {obj.making.apply ( This, ARG); Create_inter is equivalent to integrating the person} create_inter. prototype=obj;//the person to Create_inter 's prototype.return New create_inter();//Returns the object that owns the person property and method created with Create_inter. }varSTU1 =NewCreate (person,["STU1", 20]);//STU1 varSTU2 =NewCreate (person,["STU2", 21]);//STU2 varSTU3 =NewCreate (person,["Stu3", 22]);//STU3Stu1.say (); Stu2.say (); Stu3.say ();
Need to continue to think about is: Stu1,stu2,stu3 in the Say () function is a common one, or each one? Remember to verify the code.
JavaScript Building Object Focus (i)