$(function () {
var Person=function (name,work) {
var _person=new Human()
_person.name=new Names(name);
_person.work=new Work(work);
return _person
}
var person=new Person('xiao zhang','code');
console.log(person.skill)
console.log(person.name.firstName)
console.log(person.work.desc)
person.work.changeDesc('请更改描述')
console.log(person.work.desc)
});
var Human=function (param) {
this.skill=param&¶m.skill||'保密';
this.hobby=param&¶m.hobby||'保密';
}
Human.prototype ={
getSkill:function () {
return this.skill;
},
getBobby:function () {
return this.hobby;
}
}
var Names=function (name) {
var that=this;
(function (name,that) {
that.wholeName=name;
if(that.wholeName.indexOf(' ')>-1){
that.firstName=that.wholeName.slice(0,name.indexOf(' '));
that.secondName=that.wholeName.slice(name.indexOf(' '));
}
})(name,that);
}
var Work=function (work) {
var that=this;
(function (work,that) {
switch (work){
case 'code':
that.work='工程师'
break;
case 'UI':
that.work='美工'
break;
case 'teach':
that.work='教师'
break;
default:
that.work='无该岗位描述'
break;
}
})(name,that);
}
Work.prototype.changeWork=function (work) {
this.work=work;
}
Work.prototype.changeDesc=function (desc) {
this.desc=desc;
}
建造者模式顾名思义:
一个建造者,使用不同的工具堆砌出的一种模式
建造者模式归根到底可以认为是。通过不同的类加工出不同的东西,然后展示出最终的效果