Skip to content

Commit ba5186d

Browse files
committed
stage 4
1 parent cf3841f commit ba5186d

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

stages/index.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
'use strict';
22
/**
3-
* We can _structure_ the properties better, and
4-
* make the code a little easier to read by
5-
* constructing objects.
3+
* We use the `class` keyword to define a class
4+
* before we create instances of it (objects).
65
*
7-
* Our `drawRect` function no longer needs
8-
* six parameters and the code is easier to read.
6+
* We define the `Rectangle` class and create two
7+
* instances of it.
8+
*
9+
* They are then drawn as before.
910
*/
1011

11-
// create an object
12-
const rect1 = {
13-
x: 100,
14-
y: 50,
15-
width: 100,
16-
height: 200,
17-
col: 'crimson',
18-
};
19-
20-
// create another object
21-
const rect2 = {
22-
x: 300,
23-
y: 150,
24-
width: 100,
25-
height: 200,
26-
col: 'steelblue',
27-
};
12+
class Rectangle {
13+
constructor(x, y, width, height, col) {
14+
this.x = x;
15+
this.y = y;
16+
this.width = width;
17+
this.height = height;
18+
this.col = col;
19+
}
20+
}
2821

22+
// create the two rectangle objects
23+
const rect1 = new Rectangle(100, 50, 100, 200, 'crimson');
24+
const rect2 = new Rectangle(300, 150, 100, 200, 'steelblue');
2925

3026
// draw a rectangle
3127
function drawRect(c, r) {

0 commit comments

Comments
 (0)