Skip to content

Commit f9780df

Browse files
committed
stage 10
1 parent d9e8452 commit f9780df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stages/classes.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ export class Shape {
44
this.y = y;
55
this.col = col;
66
}
7+
8+
moveBy(x, y) {
9+
this.x += x;
10+
this.y += y;
11+
}
712
}
813

914
export class Rectangle extends Shape {

stages/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use strict';
22
/**
3-
* We use an array instead of four variables,
4-
* resulting in cleaner code.
3+
* Adding functions to a superclass makes them available
4+
* to all classes that extend it.
5+
*
6+
* Here, we use `moveBy()` on rectangles and circles
7+
* even though it is only defined on Shape.
58
*/
69

710
import { Circle, Rectangle } from './classes.mjs';
@@ -19,4 +22,6 @@ const ctx = document.querySelector('canvas').getContext('2d');
1922

2023
for (const s of shapes) {
2124
s.draw(ctx);
25+
s.moveBy(110, 30);
26+
s.draw(ctx);
2227
}

0 commit comments

Comments
 (0)