【问题标题】:Confused about this & getcontext js/ts and how to get around it对此和 getcontext js/ts 以及如何绕过它感到困惑
【发布时间】:2021-10-13 21:12:37
【问题描述】:

所以,我遇到了一个问题,我经常遇到不确定的错误,(在浏览器中)并且似乎无法弄清楚为什么/如何解决它。从我收集到的信息来看,关键字“this”在 js 中是一个完全令人困惑的混乱,而且在 ts 中也是如此。

这是我的问题:

export class XY
{
   property: boolean;
    //other proprs
   constructor()
    {this.property = false;}

 setproperty(e) //this is an onclick event
 {
  this.property = true;
 //my problem is that this.property doesn't refer to class member variable "property"
 }
}

即使我尝试类似 const boundGet = XY.bind.(xy),它仍然未定义且“无法访问”

如果不使用关键字“this”,我应该如何引用成员变量属性而不使其成为 const??

【问题讨论】:

标签: angular typescript ecmascript-2017


【解决方案1】:

所以,问题出在 Devextreme 的事件绑定上。 如果你想覆盖他们的数据网格控件“编辑”按钮事件,你必须传递这样的事件 [onClick]="yourfunc" 现在这显然不是标准的 (event)="blabla"。 无论背景中发生什么,都会弄乱“this”的上下文。 通过使用不同的事件解决了这个问题。

【讨论】:

    猜你喜欢
    • 2016-05-24
    • 1970-01-01
    • 2011-11-06
    • 2019-04-14
    • 2020-08-20
    • 1970-01-01
    • 2021-04-06
    • 2020-11-11
    • 1970-01-01
    相关资源
    最近更新 更多