I run code from MDN example (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields#private_methods)
class ClassWithPrivateMethod {
#privateMethod() {
return 'hello world';
}
getPrivateMessage() {
return this.#privateMethod();
}
}
const instance = new ClassWithPrivateMethod();
console.log(instance.getPrivateMessage());
// hello world
in Node.js 14 and got error:
#privateMethod() {
^
SyntaxError: Unexpected token '('
MDN contains info that private class methods are available from Node.js 12.0.0 Private fields works fine. I need same private methods. "use strict" turn on/off does not affect the error. Is there a way to make the documentation example work in Node.js?