-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3、建造者模式.js
55 lines (47 loc) · 1.21 KB
/
3、建造者模式.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Created by ducen on 2017/7/17.
* 建造者模式
*/
var Human = function(param) {
this.name = param && param.skill || '保密';
this.hobby = param && param.hobby || '保密';
}
var Named = function(name) {
//...
this.name = name;
this.firstName = name[0]//忽略处理
this.second = name[1]//忽略处理
}
var Work = function(work) {
var that = this;
switch (work){
case 'code':
that.work = "工程师";
that.workDescript = "每天沉醉于编程";
break;
case 'UI':
case 'UE':
that.work = "设计师";
that.workDescript = "设计更是似一种艺术";
break;
default:
that.work = work;
that.workDescript = "这家伙很懒什么也没留";
}
}
Work.prototype.changeWork = function(work) {
this.work = work;
}
Work.prototype.chengeDescript = function(Descript) {
this.workDescript = workDescript;
}
//TODO 备忘录
//创建者
var Person = function(name,work) {
var _person = new Human();
_person.name = new Named(name);
_person.work = new Work(work);
return _person;
}
var person = new Person('张思','code');
console.log(person);