[英]why does my functions returning “undefined”
I want to get a value from class Check but always get undefined
. 我想从Check类获取一个值,但始终
undefined
。
class Check {
static testget() {
let tester = 1;
return tester;
}
}
window.onscroll = function() {
const test = new Check();
console.log(test.testget);
};
It should show 1
on console, but I always get undefined
. 它应该在控制台上显示
1
,但我总是得到undefined
。
I will request you to spent some time on Classes: Static methods . 我将要求您花一些时间在Classs:静态方法上 。
Since the member ( testget ) is static , you can not access that with an instance ( test ) of the class, use class name. 由于成员( testget )是static ,因此您无法使用该类的实例( test )访问该成员,请使用类名。 Also specify
()
after function name to invoke the function: 在函数名称后还要指定
()
来调用该函数:
console.log(Check.testget());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.