mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
docs(class): fix typo
This commit is contained in:
parent
a837d8f2ce
commit
6880b36897
@ -986,11 +986,11 @@ console.log(getX(new C())); // 1
|
||||
|
||||
## 类的注意点
|
||||
|
||||
### 严格模式**
|
||||
### 严格模式
|
||||
|
||||
类和模块的内部,默认就是严格模式,所以不需要使用`use strict`指定运行模式。只要你的代码写在类或模块之中,就只有严格模式可用。考虑到未来所有的代码,其实都是运行在模块之中,所以 ES6 实际上把整个语言升级到了严格模式。
|
||||
|
||||
### 不存在提升**
|
||||
### 不存在提升
|
||||
|
||||
类不存在变量提升(hoist),这一点与 ES5 完全不同。
|
||||
|
||||
@ -1011,7 +1011,7 @@ class Foo {}
|
||||
|
||||
上面的代码不会报错,因为`Bar`继承`Foo`的时候,`Foo`已经有定义了。但是,如果存在`class`的提升,上面代码就会报错,因为`class`会被提升到代码头部,而`let`命令是不提升的,所以导致`Bar`继承`Foo`的时候,`Foo`还没有定义。
|
||||
|
||||
### name 属性**
|
||||
### name 属性
|
||||
|
||||
由于本质上,ES6 的类只是 ES5 的构造函数的一层包装,所以函数的许多特性都被`Class`继承,包括`name`属性。
|
||||
|
||||
@ -1022,7 +1022,7 @@ Point.name // "Point"
|
||||
|
||||
`name`属性总是返回紧跟在`class`关键字后面的类名。
|
||||
|
||||
### Generator 方法**
|
||||
### Generator 方法
|
||||
|
||||
如果某个方法之前加上星号(`*`),就表示该方法是一个 Generator 函数。
|
||||
|
||||
@ -1047,7 +1047,7 @@ for (let x of new Foo('hello', 'world')) {
|
||||
|
||||
上面代码中,`Foo`类的`Symbol.iterator`方法前有一个星号,表示该方法是一个 Generator 函数。`Symbol.iterator`方法返回一个`Foo`类的默认遍历器,`for...of`循环会自动调用这个遍历器。
|
||||
|
||||
### this 的指向**
|
||||
### this 的指向
|
||||
|
||||
类的方法内部如果含有`this`,它默认指向类的实例。但是,必须非常小心,一旦单独使用该方法,很可能报错。
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user