feat: update es6.md about private class (#76)

* feat: update es6 about private class

* update
This commit is contained in:
fw_qaq 2022-11-15 13:44:01 +08:00 committed by GitHub
parent c2cb9fa3d7
commit 8a9d9de14b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,6 +149,41 @@ class Circle extends Shape {
原型的语法糖。
请参阅: [](https://babeljs.io/learn-es2015/#classes)
### 私有类
javascript 默认字段是公共的(`public`,如果需要注明私有,可以使用(`#`
```js
class Dog {
#name;
constructor(name) {
this.#name = name;
}
printName() {
//只能在类内部调用私有字段
console.log(`你的名字是${this.#name}`)
}
}
const dog = new Dog("putty")
//console.log(this.#name)
//Private identifiers are not allowed outside class bodies.
dog.printName()
```
#### 静态私有类
```js
class ClassWithPrivate {
static #privateStaticField;
static #privateStaticFieldWithInitializer = 42;
static #privateStaticMethod() {
// …
}
}
```
Promises
--------
@ -455,6 +490,13 @@ function foo() {}
foo.name // "foo"
```
### length 属性
```js
function foo(a, b){}
foo.length // 2
```
Objects
-------