This is similiar code construction in both cases of switch except word sendPhoto/sendVideo. How I can to change it, simplify.
class Telegram {
defineMedia = 'photo';
static sendPost(ctx) {
switch (this.defineMedia){
case 'photo':
this.getUrl((urlCallback) => {
ctx.telegram.sendPhoto/*sendPhoto*/(this.#chatId,
{url: urlCallback});
});
break;
case 'video':
this.getUrl((urlCallback) => {
ctx.telegram.sendVideo/*sendVideo*/(this.#chatId,
{url: urlCallback});
});
break;
}
}
}
Telegram.sendPost();
How can I to change a switch to something like this:
this.getUrl((urlCallback) => {
ctx.telegram.(this.defineMedia = 'photo' ? sendPhoto : sendVideo )(this.#chatId,
{url: urlCallback});
});