Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Код изменения состояния каунтера (https://javascript.ru/forum/misc/84554-kod-izmeneniya-sostoyaniya-kauntera.html)

Evgeniya S 13.10.2022 01:02

Код изменения состояния каунтера
 
:help: :help: :help:
Всем, привет!
Код изменения состояния каунтера дублируется. Как лучше сделать отдельную функцию для изменения состояния каунтера и иконки, которую можно переиспользовать здесь generateCard() и при изменении состояния лайка, вызывая ее в методе numbersLikes(likes).

numbersLikes(likes) {
      this._likeCount = likes.length;
      this._numberLike.textContent = this._likeCount;
   }

   generateCard() {
      this._element = this._getTemplate(); // получаем доступ к элементу  
      this._cardImage = this._element.querySelector('.elements__mask-group');
      this._cardTitle = this._element.querySelector('.elements__sight');
      this._likeButton = this._element.querySelector('.elements__like');
      this._numberLike = this._element.querySelector('.elements__number-like');
      this._deleteButton = this._element.querySelector('.elements__delete');

      this._cardImage.src = this._image;
      this._cardTitle.textContent = this._title;
      this._cardImage.alt = this._title;
     this._numberLike.textContent = this._likeCount;

      this._checkOwner();

      this._setEventListeners();

      return this._element;
   }


Часовой пояс GMT +3, время: 23:47.