Skip to content

Commit e8d7ff9

Browse files
committed
feat: update articles
1 parent a99d381 commit e8d7ff9

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

类与对象/ES6 Class.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Polygon {}
294294

295295
### 原型方法
296296

297-
```
297+
```js
298298
class Polygon {
299299
constructor(height, width) {
300300
this.height = height;
@@ -325,19 +325,19 @@ constructor(data) {Object.assign(this, data);}const data = JSON.parse(req.respon
325325

326326
`static` 关键字用来定义类的静态方法。静态方法是指那些不需要对类进行实例化,使用类名就可以直接访问的方法。静态方法经常用来作为工具函数。
327327

328-
```
328+
```js
329329
class Point {
330-
constructor(x, y) {
331-
this.x = x;
332-
this.y = y;
333-
}
330+
constructor(x, y) {
331+
this.x = x;
332+
this.y = y;
333+
}
334334

335-
static distance(a, b) {
336-
const dx = a.x - b.x;
337-
const dy = a.y - b.y;
335+
static distance(a, b) {
336+
const dx = a.x - b.x;
337+
const dy = a.y - b.y;
338338

339-
return Math.sqrt(dx*dx + dy*dy);
340-
}
339+
return Math.sqrt(dx * dx + dy * dy);
340+
}
341341
}
342342

343343
const p1 = new Point(5, 5);
@@ -413,7 +413,7 @@ class Lion extends Cat {
413413

414414
当 ES6 类继承另一个类,被继承的类可以是通过任意表达式创建的动态类:
415415

416-
```
416+
```js
417417
// Function id() simply returns its parameter
418418
const id = x => x;
419419

0 commit comments

Comments
 (0)