-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path3-class.js
More file actions
40 lines (31 loc) · 709 Bytes
/
3-class.js
File metadata and controls
40 lines (31 loc) · 709 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
39
40
'use strict';
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
move(x, y) {
this.x += x;
this.y += y;
}
toString() {
return `[${this.x}, ${this.y}]`;
}
static from(obj) {
const { x, y } = obj;
return new Point(x, y);
}
}
const point1 = new Point(0, 0);
point1.move(1, -1);
point1.move(10, 0);
const point2 = Point.from(point1);
point2.move(-7, 25);
console.log('Point prototype:', Point.prototype);
console.log('move prototype:', Point.prototype.move.prototype);
console.log('constructor prototype:', Point.constructor.prototype);
const p1 = new Point(10, 20);
p1.move(-5, 10);
console.log(p1);
console.log(p1.toString());
console.log(`${p1}`);