-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart_two.js
More file actions
72 lines (69 loc) · 2.45 KB
/
Copy pathpart_two.js
File metadata and controls
72 lines (69 loc) · 2.45 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Aron Gassilewski | arga1535@student.su.se
* Emanuel Fuetsch | emfu2071@student.su.se
*
*/
createClass = function(className, superClassList){
theClass = {
className : className,
superClassList : superClassList,
getFunction : function(funcName){
if(this.hasOwnProperty(funcName)){
return this[funcName];
}else{
for(let c in this.superClassList){
let returnVal = this.superClassList[c].getFunction(funcName);
if(returnVal){
return returnVal;
}
}
return null;
}
},
new : function(){
instance = {
call : function(funcName, parameters){
if(this.hasOwnProperty(funcName)){
return this[funcName].apply(null, parameters);
} // ??
if(this.Class.hasOwnProperty(funcName)){
let ret = this.Class[funcName].bind(this);
return ret.apply(null, parameters);
}else{
for(let c in this.Class.superClassList){
let returnVal = this.Class.superClassList[c].getFunction(funcName);
if(returnVal){
returnVal = returnVal.bind(this);
return returnVal.apply(null, parameters);
}
}
throw className + " has no property " + funcName;
}
}
};
instance.Class = this;
return instance;
},
hasSuper : function(superclass) {
if (this.superClassList.includes(superclass)) {
return true
} else {
for (let i = 0; i < this.superClassList.length; i++) {
let hasProto = this.superClassList[i].hasSuper(superclass);
if (hasProto) {
return true;
}
}
return false;
}
},
addSuperClass : function(superclass){
if(superclass.hasSuper(this)){
throw "Circular inheritance."
}else{
this.superClassList.push(superclass);
}
}
};
return theClass;
};