Experiencing an 'undefined' error for the 'loglogMePleasePlease' function in the code snippet below.
Requesting assistance to resolve this issue.
TypeError: Cannot read property 'logMePleasePlease' of undefined
This error has left me bewildered, causing me to question my coding skills and everything I have done so far.
import {Router, Request, Response, NextFunction} from 'express';
import * as fs from 'fs';
import { db } from '../db/lowDb'
export class employeeRoute {
router: Router
constructor() {
this.router = Router();
this.init();
}
init() {
this.router.get('/', this.default);
this.logMePleasePlease('SFDSFSDF');/*This call works fine!*/
}
public logMePleasePlease(err){
console.log(err);
}
public default(req: Request, res: Response, next: NextFunction) {
/*****Error when execution gets to follwing line:
TypeError: Cannot read property 'logMePleasePlease' of undefined
******/
this.logMePleasePlease('asdad');
res.send({
status:'ok',
message:'employee api home'
});
}
}
const employee = new employeeRoute();
export default employee.router;