Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   ООП в js. Проблема (https://javascript.ru/forum/misc/68516-oop-v-js-problema.html)

MegaMutex 21.04.2017 12:06

ООП в js. Проблема
 
Пытаюсь изучить ООП javascript на реальный примерах и столкнулся с проблемой. Есть такой код:
function Widget(containerSelector) {
    this.$container = $(containerSelector);
    this.$widgetIco = this.$container.find('.js-box-ico');
    this.$cell = this.$container.find('.js-cell');
    this.cellRedClass = this.$cell.data('cellRedClass');
    this.bindEvents();
}

Widget.prototype.bindEvents = function() {
    this.$widgetIco
        .on('mouseenter', this.addCell.bind(this))
        .on('mouseleave', this.removeCell.bind(this));
};

Widget.prototype.addCell = function() {
    // Добавить класс к наведенному элементу.
    выбранный элемент при ховере.addClass(this.cellRedClass);
};

$(function() {
    new Widget('.box');
});


Не могу понять, как, к примеру, добавить класс в Widget.prototype.addCell к текущему наведенному мышкой элемменту .js-box-ico?

Rise 21.04.2017 14:18

MegaMutex, у jquery так сказать есть свой ООП-стиль Plugins, хороший тон его придерживаться, если пишешь на jquery.


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