-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharray.js
47 lines (41 loc) · 857 Bytes
/
array.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
import { cachedValueOf } from '../operator';
export const hijackArray = ArrayClass => {
const { prototype } = ArrayClass;
Object.defineProperty(prototype, 'x', {
get() {
return this[0] || 0;
},
set(x) {
this[0] = x;
},
configurable: true
});
Object.defineProperty(prototype, 'y', {
get() {
return this[1] || 0;
},
set(y) {
this[1] = y;
},
configurable: true
});
Object.defineProperty(prototype, 'z', {
get() {
return this[2] || 0;
},
set(z) {
this[2] = z;
},
configurable: true
});
cachedValueOf(ArrayClass);
Object.defineProperty(prototype, 'len', {
get() {
return (this[0] ** 2 + this[1] ** 2 + this[2] ** 2) ** (1 / 2);
},
set() {
throw new Error('set len not allowed');
},
configurable: true
});
};