In my Deno Typescript project, I have the following class hierarchy:
AccountPutController.ts
export class AccountPutController extends HttpController {
constructor(commandBus: CommandBus) {
super(commandBus)
}
async handle({ params, request, response } : {
params: { id: string }
request: any
response: any
}
) {
const { value : requestBody } = await request.body()
super.dispatch(
new CreateAccountCommand(
params.id,
requestBody.username,
requestBody.emailAddress,
requestBody.password
)
)
response.status = 201
}
}
HttpController.ts
export abstract class HttpController {
private readonly commandBus: CommandBus
constructor(commandBus: CommandBus) {
this.commandBus = commandBus
}
dispatch(command: Command) {
if(this === undefined) {
console.log("This is undefined")
return
}
this.commandBus.dispatch(command)
}
}
The condition "this === undefined" is causing confusion. Can anyone explain why it evaluates true and how to prevent it?