【发布时间】:2023-04-09 06:14:01
【问题描述】:
按照这个solution我有以下课程:
com.temp.System = class {
static initialize() {
this.foo = 9;
console.log("foo 1 is: " + this.foo);
}
static testMe() {
console.log("foo 2 is: " + this.foo);
}
}
我就是这样使用它的:
{
const System = com.temp.System;
System.initialize();
System.testMe();
}
这是输出:
foo 1 is: 9
foo 2 is: 9
我有两个问题:
- 在此类解决方案中创建静态文件的最佳方法是什么?
- 为什么
this.foo有效,尽管我没有创建此类的实例?
【问题讨论】:
-
1.你已经创建了那些 2。因为
System是一个对象,JS 中的对象可能有属性。