Hi i want to call a method in another method of the same class.
// authentication.js
var Usermgmt = require('./usermgmt');
class authentication extends Usermgmt {
#session = New Object();
constructor() {
super();
}
auth(username, password) {
console.log(value);
return true;
}
_setSession() {
this.#session.name = "Session Name";
this.test();
}
}
module.exports = authentication;
// usermgmt.js
class usermgmt {
constructor() {
}
test(){
console.log("test parent");
return "test";
}
}
module.exports = usermgmt;
// index.js
var authentication = require('authentication');
let auth = new authentication();
if(auth.auth(req.body.username, req.body.password)) {
console.log("all fine");
}
I get the error TypeError: Cannot read property '_B' of null
Any idea to avoide this? Also i want to call a function in the parent class.
Also find this example https://rfrn.org/~shu/2018/05/02/the-semantics-of-all-js-class-elements.html
class Ex22_Base {
#privateMethod() { return 42; }
}
class Ex22_Sub extends Ex22_Base {
#privateMethod() {
assertThrows(() => super.#privateMethod(), TypeError);
}
#privateMethodTwo() {
this.#privateMethod();
}
publicMethod() {
this.#privateMethodTwo();
}
constructor() {
this.#privateMethod();
}
}
Thats is what i want to do. But the # don't work in my class and i get SyntaxError: Unexpected token '('
and when i call a method in method of the same class i get TypeError: Cannot read property of null