-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.js
More file actions
41 lines (32 loc) · 737 Bytes
/
Factory.js
File metadata and controls
41 lines (32 loc) · 737 Bytes
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
/**
* Created by tay81084 on 15/11/3.
*/
var CarMaker = function(){};
CarMaker.prototype.dirve = function(){
return "I have" + this.door + "doors";
};
CarMaker.factory = function(type){
var cr = type,
newcar;
if(typeof CarMaker[cr] !== "function"){
throw{
name:"Error",
Message: cr + "does not exist"
};
}
if(typeof CarMaker[cr].prototype.drive !== "function"){
CarMaker[cr].prototype = new CarMaker();
}
newcar = new CarMaker[cr]();
return newcar;
}
CarMaker.Compact = function(){
this.doors = 4;
}
CarMaker.Convertible = function(){
this.doors = 2;
}
CarMaker.SUV = function(){
this.doors = 24;
}
module.exports = CarMaker;