Skip to content

Commit f30fd14

Browse files
committed
update code.
1 parent f0847c6 commit f30fd14

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

README-zh-CN.md

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,17 +1324,9 @@ class Shape {
13241324
}
13251325

13261326
class Rectangle extends Shape {
1327-
constructor() {
1327+
constructor(width, height) {
13281328
super();
1329-
this.width = 0;
1330-
this.height = 0;
1331-
}
1332-
1333-
setWidth(width) {
13341329
this.width = width;
1335-
}
1336-
1337-
setHeight(height) {
13381330
this.height = height;
13391331
}
13401332

@@ -1344,12 +1336,8 @@ class Rectangle extends Shape {
13441336
}
13451337

13461338
class Square extends Shape {
1347-
constructor() {
1339+
constructor(length) {
13481340
super();
1349-
this.length = 0;
1350-
}
1351-
1352-
setLength(length) {
13531341
this.length = length;
13541342
}
13551343

@@ -1360,21 +1348,12 @@ class Square extends Shape {
13601348

13611349
function renderLargeShapes(shapes) {
13621350
shapes.forEach((shape) => {
1363-
switch (shape.constructor.name) {
1364-
case 'Square':
1365-
shape.setLength(5);
1366-
break;
1367-
case 'Rectangle':
1368-
shape.setWidth(4);
1369-
shape.setHeight(5);
1370-
}
1371-
13721351
const area = shape.getArea();
13731352
shape.render(area);
13741353
});
13751354
}
13761355

1377-
const shapes = [new Rectangle(), new Rectangle(), new Square()];
1356+
const shapes = [new Rectangle(4, 5), new Rectangle(4, 5), new Square(5)];
13781357
renderLargeShapes(shapes);
13791358
```
13801359
**[⬆ 返回顶部](#代码整洁的-javascript)**

0 commit comments

Comments
 (0)