We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7dbca2b commit a342ebfCopy full SHA for a342ebf
docs/class.md
@@ -844,7 +844,7 @@ class C {
844
}
845
```
846
847
-上面示例中,`in`运算符判断某个对象是否有私有属性`#foo`。它不会报错,而是返回一个布尔值。
+上面示例中,`in`运算符判断某个对象是否有私有属性`#brand`。它不会报错,而是返回一个布尔值。
848
849
这种用法的`in`,也可以跟`this`一起配合使用。
850
@@ -853,12 +853,21 @@ class A {
853
#foo = 0;
854
m() {
855
console.log(#foo in this); // true
856
- console.log(#bar in this); // false
857
858
859
860
861
-注意,判断私有属性时,`in`只能用在类的内部。
+注意,判断私有属性时,`in`只能用在类的内部。另外,判断所针对的私有属性,一定要先声明,否则会报错。
+
862
+```javascript
863
+class A {
864
+ m() {
865
+ console.log(#foo in this); // 报错
866
+ }
867
+}
868
+```
869
870
+上面示例中,私有属性`#foo`没有声明,就直接用于`in`运算符的判断,导致报错。
871
872
子类从父类继承的私有属性,也可以使用`in`运算符来判断。
873
0 commit comments