-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
62 lines (46 loc) · 1.04 KB
/
test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'bpo enable';
console.log('hello, world!');
class Point {
x = 0;
y = 0;
constructor(_x, _y) {
if(_x) this.x = _x;
if(_y) this.y = _y;
}
toString = () => {
return 'Point(' + this.x + ', ' + this.y + ')';
}
operatorAdd = (b) => {
const a = this;
return new Point(a.x + b.x, a.y + b.y);
}
operatorMul = (b) => {
const a = this;
return new Point(a.x * b, a.y * b);
}
operatorLess = (b) => {
const a = this;
if(a.x <= b.x && a.y <= b.y && (a.x < b.x || a.y < b.y)) return true;
else return false;
}
operatorLessEqual = (b) => {
const a = this;
if(a.x <= b.x && a.y <= b.y) return true;
else return false;
}
operatorEqual = (b) => {
const a = this;
return a.x == b.x && a.y == b.y;
}
};
let a = new Point(1, 2), b = new Point(3, 4);
console.log((a + b * 3).toString());
let c = 'A string!';
String.prototype.operatorMul = function(times) {
console.log(times);
let ret = '';
for(let i = 1; i <= times; ++i) ret += this;
return ret;
};
let d = c * 3;
console.log(d);