-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmultiple_inheritence.js
More file actions
76 lines (72 loc) · 1.94 KB
/
multiple_inheritence.js
File metadata and controls
76 lines (72 loc) · 1.94 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
72
73
74
75
76
var Proxy = require("../lib/proxy")
var PrototypeChain = function(prototypes) {
return Proxy.create({
//GETTER
"get": function(holder,property){
for(var i=prototypes.length-1;i>=0;i--) {
var proto = prototypes[i]
if(property in proto) {
return proto[property]
}
}
return null
}
//SETTER
, "set": function(holder,property,value) {
//DONT SET THE CHAINS VALUES!
}
//FOREACH
, "enumerate": function() {
var properties={}
for(var i=prototypes.length-1;i>=0;i--) {
var proto = prototypes[i]
var keys = Object.getOwnPropertyNames(proto)
keys = keys.filter(function(item){
return !(item in properties)
})
keys.forEach(function(item){
properties[item]=proto[item]
})
}
return Object.getOwnPropertyNames(properties)
}
, "has": function(property) {
return prototypes.some(function(item){
return property in item
} )
}
, "delete": function(ArgInfo) {
}
}, prototypes[prototypes.length-1] )
}
function mySuper() {}
mySuper.prototype.fly = function() {
console.log("SOARING AT THE SPEED OF SOUND")
}
mySuper.prototype.run = function() {
console.log("RUNNING FOR 10 HOURS")
}
function mySuperduper() {}
mySuperduper.prototype = new mySuper
mySuperduper.prototype.fly = function() {
console.log("SOARING AT THE SPEED OF LIGHT")
}
function myIdentity() {}
myIdentity.prototype.id = function() {
console.log("I am a mild mannered human")
}
var proto = PrototypeChain([new mySuperduper,new myIdentity])
function myself(){}
myself.prototype = proto
var me = new myself
me.fly()//from superduper
me.run()//from super
me.id()//from identity
console.log("Am I an Identity? "+(me instanceof myIdentity))
//only one chain can be used for instanceof T_T
console.log("Am I an Super? "+(me instanceof mySuperduper))
//prototype chain changes are preserved!
mySuper.prototype.run = function() {
console.log("Acting mild mannered I walk")
}
me.run()