라는 클래스를 정의했습니다 Plan
. 다음은 코드입니다.
class Plan {
async getPlanText(ctx) {
return await this.getPlanDetails(ctx);
}
async getPlanDetails(ctx) {
return ...
}
}
exports.Plan = Plan;
나는 얻다:
this.getPlanDetails는 함수가 아닙니다.
내가 뭘 잘못 했어?
나는 Plan
이런 식으로 수업을 사용했습니다 .
const { Plan } = require('./controllers/plan.controller');
let planController = new Plan();
console.log(planController.getPlanText('my context'));
이 시도. 기본적으로 전달하는 동안 함수를 클래스에 바인딩해야 종속성을 가져올 위치를 알 수 있습니다. 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind에서 읽을 수 있습니다.
const planController = new Plan();
const menu = new TelegraphInlineMenu(planController.getPlanText.bind(planController))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다