我想从Check类获得一个值,但总是得到undefined
。
class Check {
static testget() {
let tester = 1;
return tester;
}
}
window.onscroll = function() {
const test = new Check();
console.log(test.testget);
};
它应该在控制台上显示1
,但我总是得到undefined
。
答案 0 :(得分:1)
我会要求您花一些时间在Classes: Static methods上。
由于成员( testget )是 static ,因此您无法使用该类的实例( test )访问该成员,请使用< em> class 名称。另外,在函数名称后指定()
来调用该函数:
console.log(Check.testget());