From 7a4b4570f05087421f1ed2d4020789c3a2a02951 Mon Sep 17 00:00:00 2001 From: jaywcjlove Date: Tue, 15 Nov 2022 05:45:01 +0000 Subject: [PATCH] feat: update es6.md about private class (#76) * feat: update es6 about private class * update 8a9d9de14b430904b2e97f50e486f6e636443ac5 --- CONTRIBUTORS.svg | 4 +++- docs/es6.html | 34 +++++++++++++++++++++++++++++++++- index.html | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.svg b/CONTRIBUTORS.svg index 85dfdbd5..53fd0787 100644 --- a/CONTRIBUTORS.svg +++ b/CONTRIBUTORS.svg @@ -3,7 +3,7 @@ xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="740" - height="52" + height="104" > @@ -34,5 +34,7 @@ + + \ No newline at end of file diff --git a/docs/es6.html b/docs/es6.html index ce4d9f06..d79c9aa2 100644 --- a/docs/es6.html +++ b/docs/es6.html @@ -41,7 +41,7 @@

快速浏览 ES2015、ES2016、ES2017、ES2018 及以后的 JavaScript 新特性

常用

块范围

Let

@@ -132,6 +132,34 @@

原型的语法糖。 请参阅:

+

私有类

+

javascript 默认字段是公共的(public),如果需要注明私有,可以使用(#

+
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()
+
+

静态私有类

+
class ClassWithPrivate {
+  static #privateStaticField;
+  static #privateStaticFieldWithInitializer = 42;
+
+  static #privateStaticMethod() {
+    // …
+  }
+}
+

Promises

做出承诺

new Promise((resolve, reject) => {
@@ -322,6 +350,10 @@
 
function foo() {}
 foo.name // "foo"
 
+

length 属性

+
function foo(a, b){}
+foo.length // 2
+

Objects

速记语法

module.exports = { hello, bye }
diff --git a/index.html b/index.html
index 62444cb9..3b6686ce 100644
--- a/index.html
+++ b/index.html
@@ -463,6 +463,9 @@
 
   coderduan
 
+
+  cool9203
+
 
   hua03