首页 > 解决方案 > 如何正确引用类constructor()中声明的数据?

问题描述

这是代码快照:

class UIController {
    constructor() {
        let eleNodes = new EleNodes()
        this.idsAndClasses = eleNodes.idsAndClasses
        this.nodes = eleNodes.nodes
    }
    async OpenCloseForm() {
        let formContainer = this.nodes.solcomForm
        //...other code
    }
}

当我稍后OpenCloseForm在单击时指定为函数时,this不再引用 che 类,而是按下按钮this.nodes的变为的上下文。this这里是点击设置:

//this in this case references to the object setup in yet another class
//where I also call this event handler
this.uiCtrl.solcomForm.on("click", this.uiCtrl.OpenCloseForm)

有没有办法引用回类中的实际数据?

ps:我已经查看了标记的问题,它确实缺少上下文,在这种情况下使用类而不是函数,所以我无法从另一个上下文中得出解决方案。

标签: javascriptclassecmascript-6constructor

解决方案


推荐阅读