why class private property still can be accessed in chrome 114?

96 Views Asked by At
class Person {
  #name = 'Ergonomic brand checks for Private Fields';
  aa=1
  static check(obj) {
    return #name in obj;
  }
}

var p = new Person()

p.#name can be accessed! means not supported...

p.#age has error report, means supported... enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

From mdn:

It is a syntax error to refer to # names from outside of the class. It is also a syntax error to refer to private properties that were not declared in the class body

And also

Note: Code run in the Chrome console can access private properties outside the class. This is a DevTools-only relaxation of the JavaScript syntax restriction.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields