We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d9e8452 commit f9780dfCopy full SHA for f9780df
2 files changed
stages/classes.mjs
@@ -4,6 +4,11 @@ export class Shape {
4
this.y = y;
5
this.col = col;
6
}
7
+
8
+ moveBy(x, y) {
9
+ this.x += x;
10
+ this.y += y;
11
+ }
12
13
14
export class Rectangle extends Shape {
stages/index.js
@@ -1,7 +1,10 @@
1
'use strict';
2
/**
3
- * We use an array instead of four variables,
- * resulting in cleaner code.
+ * Adding functions to a superclass makes them available
+ * to all classes that extend it.
+ *
+ * Here, we use `moveBy()` on rectangles and circles
+ * even though it is only defined on Shape.
*/
import { Circle, Rectangle } from './classes.mjs';
@@ -19,4 +22,6 @@ const ctx = document.querySelector('canvas').getContext('2d');
19
22
20
23
for (const s of shapes) {
21
24
s.draw(ctx);
25
+ s.moveBy(110, 30);
26
+ s.draw(ctx);
27
0 commit comments