V
V
Vladimir Golub2020-12-24 11:06:25
typescript
Vladimir Golub, 2020-12-24 11:06:25

How to use a static method inside a class via this?

Can't access via this, only via Test.getName(). Is there an analogue of self like in php ?

class Test {

  static getName() {
    return 'Jack';
  }

  static getFullName() {
    return `${ this.getName } Ivanov`
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2020-12-24
@RazerVG

Everything works fine:
https://www.typescriptlang.org/play?#code/MYGwhgzh...
Probably because the parentheses in the method call were forgotten

A
abberati, 2020-12-24
@abberati

No way. Only via Test.getName()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question