【发布时间】:2019-02-25 19:08:00
【问题描述】:
我有num1: number,然后
constructor(){
...
this.num1 = 0;
}
在一个类中。
但是当在函数console.log(this.num1) 或console.log(typeof this.num1) 中登录时,我两次都得到undefined。
为什么我的变量的值在这里未定义?
【问题讨论】:
-
嗨!请查看有关 how to ask a good question 的指南以及什么构成 minimal reproducible example。我猜您遇到问题的函数的
this值与您预期的不同,但如果没有更多信息,很难更具体。祝你好运! -
方法是如何被调用的?正如@jcalz 提到的,
this的值很可能不是该类的实例。 -
你点击一个按钮,然后通过调用前面提到的需要当前类实例的num1的函数来处理这个事件
标签: typescript console namespaces undefined