Как редактировать свойство в JavaScript классе функций? - PullRequest
1 голос
/ 09 апреля 2020

У меня есть этот класс на основе чистого javascript:

var DrawFeatureP = /*@__PURE__*/(function (Draw) {
    function DrawFeatureP() {
        debugger
        Draw.call(this, {
            source: new ol.layer.Vector({ source: new ol.source.Vector() }),
            type: 'change this property from function in pottom'
        });

        document.getElementById('lineToggle').onclick = this.handleDrawFeature.bind(this);
     }


    if (Draw) DrawFeatureP.__proto__ = Draw;
    DrawFeatureP.prototype = Object.create(Draw && Draw.prototype);
    DrawFeatureP.prototype.constructor = DrawFeatureP;

    DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
        //when is function is fired how ca i set 'type' property?
    };

    return DrawFeatureP;
}(ol.interaction.Draw));

Когда эта функция запущена:

   DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
            //when is function is fired how ca I set 'type' property?
        };

Мне нужно изменить свойство 'type':

type: 'change this property from function in the bottom'

Мой вопрос: как редактировать свойство типа из функции handleDraw?

1 Ответ

1 голос
/ 09 апреля 2020

Поскольку вы связываете this при назначении обработчика onclick, вы можете использовать this.type в функции обработчика.

    DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
        this.type = "new type";
    };
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...