为什么我的函数返回 "undefined"
why does my functions returning "undefined"
我想从 class 中获取一个值,但总是得到 undefined
.
class Check {
static testget() {
let tester = 1;
return tester;
}
}
window.onscroll = function() {
const test = new Check();
console.log(test.testget);
};
它应该在控制台上显示 1
,但我总是得到 undefined
。
我会请你花一些时间在Classes: Static methods上。
由于成员 (testget) 是 static,您无法使用实例 (test) 的 class,使用 class 名称。还要在函数名后指定()
来调用函数:
console.log(Check.testget());
我想从 class 中获取一个值,但总是得到 undefined
.
class Check {
static testget() {
let tester = 1;
return tester;
}
}
window.onscroll = function() {
const test = new Check();
console.log(test.testget);
};
它应该在控制台上显示 1
,但我总是得到 undefined
。
我会请你花一些时间在Classes: Static methods上。
由于成员 (testget) 是 static,您无法使用实例 (test) 的 class,使用 class 名称。还要在函数名后指定()
来调用函数:
console.log(Check.testget());