There is a class, the necessary part of which looks like this:
class ApiController { constructor() { this.all_languages = 'boards'; this.all_boards = 'languages'; } langs(req, res, next) { console.log(this); res.end(this.all_languages); } }; var api_controller = new ApiController(); module.exports = api_controller;
Next, an instance of this class is imported into another file, where it is called in a router like this:
var api = require('../controllers/api'); router.get('/langs', api.langs);
However, the request [TypeError: Cannot read property 'all_languages' of undefined]
error, and in this
in the console it is displayed as undefined
. If you call this method on the instance in the same class where it was created, then everything works fine. What can be wrong?