如何在JavaScript函数类中编辑属性?

如何在JavaScript函数类中编辑属性?,javascript,openlayers,Javascript,Openlayers,我有一个基于纯javascript的类: var DrawFeatureP = /*@__PURE__*/(function (Draw) { function DrawFeatureP() { debugger Draw.call(this, { source: new ol.layer.Vector({ source: new ol.source.Vector() }), type: 'change th

我有一个基于纯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: 'change this property from function in the bottom'

我的问题是如何从handleDraw函数编辑类型属性?

由于在分配
onclick
处理程序时绑定了
this
,因此可以在处理程序函数中使用
this.type

    DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
        this.type = "new type";
    };

在我看来,这个功能是不纯洁的。因为有dom操作。依我拙见如果有人非常感谢你这个职位,请改变我的想法。但是上面的例子不起作用。你知道原因是什么吗?