-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathpriori-incantatem.js
More file actions
38 lines (31 loc) · 769 Bytes
/
priori-incantatem.js
File metadata and controls
38 lines (31 loc) · 769 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
const MAX_PRIOR_SPELLS = 13;
class Wand {
constructor(spells = {}) {
this.casted = [];
Object.assign(this, spells);
return new Proxy(this, {
get: (target, property) => {
const value = target[property];
if (typeof value === 'function') {
target.casted.unshift(property);
}
return value;
}
});
}
prioriIncantatem() {
return this.casted.slice(1, MAX_PRIOR_SPELLS + 1);
}
deletrius() {
this.casted = ['deletrius'];
}
}
const w = new Wand({
expelliarmus: function () {},
alohomora: function () {},
avadaKedavra: function () {}
});
w.alohomora();
w.expelliarmus();
w.avadaKedavra();
console.log(w.prioriIncantatem(), ['avadaKedavra', 'expelliarmus', 'alohomora']);