Builder: The building layer of a complex object is separated from its presentation layer, and the same component process can be represented differently.
//Create a human varHuman = function(param){ //Skills This. Skill = param && Parma.skill | |' confidentiality ';//Hobbies This. Hobby = param && Param.hobby | |' confidentiality '; }//Human-like prototype methodHuman.prototype = {Getskill: function(){ return This. Skill; }, Gethobby: function(){ return This. Hobby; } }//Instantiate name Class varNamed = function(name){ varthat = This;//Builder //constructor resolves the first and last names of a name( function(name,that){That.wholename = name;if(Name.indexof ("') >-1) {that. FirstName = Name.slice (0, Name.indexof ("')); That.secondname = Name.slice (Name.indexof ("')); } }) }//instantiation of position classes varWork = function(work){ varthat = This;//Builder... }//Update the desired positionWork.prototype.changeWork = function(work){ This. Work = Work; }//Add a description of the position
/****应聘者建造者*参数 name *参数 work**/varfunction(name,work){ //创建应聘者缓存对象 varnew Human(); //创建应聘者姓名解析对象 _person.name = New Named(name); //创建应聘者期望职位 new Work(work); //将创建者返回 return _person;}
How to use
varnew Person(‘xiao ming‘,‘code‘);
Factory mode creates an object, and he pursues the result of creation, and there is no other way, so that is just a real process of creation. And the builder pattern is different, it's not just the results of the creation, but it's also involved in the process of creating it. The details of the specific implementation created are also involved in the intervention, which can be said to create more complex objects, or that this pattern creates a composite object.
JavaScript design mode--builder