JavaScript design mode--builder

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.