Y
Y
Yura Komarov2020-02-14 19:05:05
Yii
Yura Komarov, 2020-02-14 19:05:05

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

2 answer(s)
C
coderisimo, 2019-06-09
@nnkrasovok

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]);

Y
Yura Komarov, 2020-02-14
@Yurajun

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 question

Ask a Question

731 491 924 answers to any question