File tree Expand file tree Collapse file tree 1 file changed +0
-40
lines changed
Expand file tree Collapse file tree 1 file changed +0
-40
lines changed Original file line number Diff line number Diff line change @@ -871,46 +871,6 @@ class A {
871871
872872上面示例中,私有属性` #foo ` 没有声明,就直接用于` in ` 运算符的判断,导致报错。
873873
874- 子类从父类继承的私有属性,也可以使用` in ` 运算符来判断。
875-
876- ``` javascript
877- class A {
878- #foo = 0 ;
879- static test (obj ) {
880- console .log (#foo in obj);
881- }
882- }
883-
884- class SubA extends A {};
885-
886- A .test (new SubA ()) // true
887- ```
888-
889- 上面示例中,` SubA ` 从父类继承了私有属性` #foo ` ,` in ` 运算符也有效。
890-
891- 注意,` in ` 运算符对于` Object.create() ` 、` Object.setPrototypeOf ` 形成的继承,是无效的,因为这种继承不会传递私有属性。
892-
893- ``` javascript
894- class A {
895- #foo = 0 ;
896- static test (obj ) {
897- console .log (#foo in obj);
898- }
899- }
900- const a = new A ();
901-
902- const o1 = Object .create (a);
903- A .test (o1) // false
904- A .test (o1 .__proto__ ) // true
905-
906- const o2 = {};
907- Object .setPrototypeOf (o2, a);
908- A .test (o2) // false
909- A .test (o2 .__proto__ ) // true
910- ```
911-
912- 上面示例中,对于修改原型链形成的继承,子类都取不到父类的私有属性,所以` in ` 运算符无效。
913-
914874## 静态块
915875
916876静态属性的一个问题是,如果它有初始化逻辑,这个逻辑要么写在类的外部,要么写在` constructor() ` 方法里面。
You can’t perform that action at this time.
0 commit comments