【发布时间】:2020-06-18 10:26:52
【问题描述】:
我一直在这里寻找答案,但我找不到任何答案,但无论如何我的问题是如何在已在其他方法中声明和初始化但在同一个类中的方法中获取数组。我将通过展示我想要实现的目标以及到目前为止我已经尝试过的内容来更清楚地说明这一点。
Javascript:
class SomeClass {
method1() {
var array = new array();
//its actually a 2d array and it is being initialised here but for simplicity this isn't
//necessary in the example.
}
method2() {
// --> Here i want to access the array and it's contents.
//I have tried this:
this.array;
//and
array;
}
}
但是当我尝试 this.array 时,我得到“无法准备好未定义的属性”;
【问题讨论】:
-
不建议使用没有构造函数的类
标签: javascript arrays class oop 2d