-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path2-prototype.js
More file actions
33 lines (25 loc) · 655 Bytes
/
2-prototype.js
File metadata and controls
33 lines (25 loc) · 655 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
'use strict';
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.from = function(obj) {
const { x, y } = obj;
return new Point(x, y);
};
Point.prototype.move = function(x, y) {
this.x += x;
this.y += y;
};
Point.prototype.toString = function() {
return `[${this.x}, ${this.y}]`;
};
console.log('function prototype:', (function() {}).prototype);
console.log('lambda prototype:', (() => {}).prototype);
console.log('Point prototype:', Point.prototype);
console.log('move prototype:', Point.prototype.move.prototype);
const p1 = new Point(10, 20);
p1.move(-5, 10);
console.log(p1);
console.log(p1.toString());
console.log(p1 + '');