Static variables are initialized when you create your class, while constructor runs after using new Test1(1)
. It means that commonParam
takes the value before you run class constructor and this.param1
is actually null.
You can try to redefine static variable in constructor like:
constructor(param1) {
this.param1=param1;
Test1.commonParam = [
['Test1', ['Test1', 'Test2', param1]]
];
console.log(`Test1 param1: ${this.param1}`);
};
Remember that every single object will modify this static variable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…