Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29d8fa3

Browse files
committed
修正类与接口章节
1 parent 3ea1737 commit 29d8fa3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

advanced/class-and-interfaces.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ function printPoint(p: Point) {
131131
console.log(p.x, p.y);
132132
}
133133

134-
const p = new Point(1, 2);
135-
136-
printPoint(p);
134+
printPoint(new Point(1, 2));
137135
```
138136

139137
这个例子实际上可以等价于:
@@ -157,9 +155,7 @@ function printPoint(p: PointInstanceType) {
157155
console.log(p.x, p.y);
158156
}
159157

160-
const p = new Point(1, 2);
161-
162-
printPoint(p);
158+
printPoint(new Point(1, 2));
163159
```
164160

165161
上例中我们新声明的 `PointInstanceType` 类型,与声明 `class Point` 时创建的 `Point` 类型是等价的。
@@ -193,7 +189,7 @@ let point3d: Point3d = {x: 1, y: 2, z: 3};
193189

194190
换句话说,我们实际上是定义了一个接口 `Point3d` 继承另一个接口 `PointInstanceType`
195191

196-
所以这种用法和接口继承接口没有什么本质的区别
192+
所以「接口继承类」和「接口继承接口」没有什么本质的区别
197193

198194
值得注意的是,`PointInstanceType` 相比于 `Point`,缺少了 `constructor` 方法,这是因为声明 `Point` 类时创建的 `Point` 类型是不包含构造函数的。另外,除了构造函数是不包含的,静态属性或静态方法也是不包含的(实例的类型当然不应该包括构造函数、静态属性或静态方法)。
199195

@@ -234,7 +230,7 @@ let p2: PointInstanceType;
234230

235231
上例中最后的类型 `Point` 和类型 `PointInstanceType` 是等价的。
236232

237-
也就是说,在接口继承类的时候,也只会继承它的实例属性和实例方法。
233+
同样的,在接口继承类的时候,也只会继承它的实例属性和实例方法。
238234

239235
## 参考
240236

0 commit comments

Comments
 (0)