a static method just has the prefix static
class UnitTest {}
class TestFactory {
makeTest() { return new UnitTest(); }
}
assert.ok(TestFactory.makeTest() instanceof UnitTest);the method name can be dynamic/computed at runtime
class UnitTest {}
const methodName = 'makeTest';
class TestFactory {
static [methodName]() { return new UnitTest(); }
}
assert.ok(TestFactory.createTest() instanceof UnitTest);
for accessors
a getter name can be static, just prefix it with static
class UnitTest {
get testType() { return 'unit'; }
}
assert.equal(UnitTest.testType, 'unit');even a static getter name can be dynamic/computed at runtime
const type = 'test' + 'Type';
class IntegrationTest {
get type() { return 'integration'; }
}
assert.ok('testType' in IntegrationTest);
assert.equal(IntegrationTest.testType, 'integration');