Plant model creating abstract object-specific process, the following sample code shows Plant type:
<! DOCTYPE HTML> <HTML> <head> <title> plant model </ title> <Script type = "text / JavaScript"> // plant model - creating an object in detail with specific interface functions wrap function createStudent (name, Age, Sex) { // the object function to build a factory var O = new new Object (); o.name = name; o.age = Age; o.sex = Sex; o.sayName = function () { Alert ( the this .name ); }; return O; } var = createStudent STU1 ( "Lucy", 10, "Girl" ); var STU2 = createStudent ( "Bob",. 9, "Boy" ); Alert (stu1.sayName === stu2.sayName); // to false // advantages : creating a plurality of similar objects to solve the problem @ disadvantages: unresolved object recognition problem (i.e., how to know the type of an object) </ Script> </ head> <body> </ body> </ HTML>
Partly from "JavaScript Advanced Programming (3rd Edition)"