Answer the question
In order to leave comments, you need to log in
How to bind a function within a function using bind?
Good evening everyone.
Can you please tell me how to pass or bind the sendReview function to the sendModal function? Because I need to call callback in another class.
class ModalSignInSms {
constructor() {
this.$modalBtnSend = $('.js-btn');
}
sendModal = async (e, callback) => {
e.preventDefault();
callback() // Нужно вызвать !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
class SendReview extends ModalSignInSms {
constructor(el) {
super();
// Возник вопрос
// Как передать или привязать в функцию sendModal функцию sendReview
this.$modalBtnSend.on('click', this.sendModal.bind(this.sendReview));
}
sendReview = async () => {
console.log('callback');
}
}
Answer the question
In order to leave comments, you need to log in
You can try wat so wat (+ variations):
use yii\helpers\Url;
$url = Url::to(['site/projects', 'ProjectSearch[id_categories]'=>2]);
// если нужна ссылка
use yii\helpers\Html;
echo Html::a("Tекст", ['site/projects', 'ProjectSearch[id_categories]'=>2]);
class ModalSignInSms {
constructor() {
this.$modalBtnSend = $('.js-btn');
}
async sendModal(e) {
e.preventDefault();
console.log('form sent')
// something happening
}
}
class SendReview extends ModalSignInSms {
constructor(el) {
super();
this.$modalBtnSend.on('click', async (e) => {
await this.sendModal(e);
await this.sendReview();
});
}
async sendReview() {
console.log('review sent');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question