File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ export class Shape {
4
4
this . y = y ;
5
5
this . col = col ;
6
6
}
7
+
8
+ moveBy ( x , y ) {
9
+ this . x += x ;
10
+ this . y += y ;
11
+ }
7
12
}
8
13
9
14
export class Rectangle extends Shape {
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
/**
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.
5
8
*/
6
9
7
10
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 ) ;
22
27
}
You can’t perform that action at this time.
0 commit comments