我想将类放在class属性中,但是当我将其放入属性中时,该类似乎变得不确定。
import { Request, Response, NextFunction, Router } from 'express';
import Controller from 'some-file';
import *some-class* from 'some-file';
class AuthenticationController implements Controller {
public path = '/auth';
public router = Router();
*some-property* = *some-class*;
constructor() {
this.initializeRoutes();
this.some-property = new some-class()
}
public initializeRoutes = () => {
this.router.post(`${this.path}/indihome`, this.loginByIndihomeId);
}
/**
* @access public
* @param {string} req.body.userId
* @return {object} Object Token
*/
public async loginByIndihomeId(request: Request, response: Response, next: NextFunction) {
var { userId } = request.body;
try {
let stbUserProfile = await this.*some-property*.getProfileFromIndihomeId(userId);
response.status(200).json(stbUserProfile)
} catch (error) {
next(error);
}
}
}
export default AuthenticationController;
我试图将其放在教室外面,并且可以正常工作。
...
const some-property = new some-class;
class AuthenticationController implements Controller {
...
但是,我想将其放在属性中。 有没有办法解决这个问题?