elpddev
elpddev

Reputation: 4494

Short referencing a static function from an instance method of the same class in typescript

Referencing the full qualified name of the static function works.

class Shape {
  spin {
    Shape.log("something");
  }

  static log(text: string) {
  }
}

Is there a short way to reference the static "log" function ? Without the full class name ?

Upvotes: 1

Views: 147

Answers (2)

Nitzan Tomer
Nitzan Tomer

Reputation: 164397

You can create a function that calls Shape.log:

class Shape {
    spin() {
        log("something");
    }

    static log(text: string) {}
}

function log(message: string) {
    Shape.log(message)
}

Upvotes: 1

James Monger
James Monger

Reputation: 10685

No, there is currently no shorthand to access the static function in the local object.

As in your example, you must use the fully-qualified name.

Upvotes: 0

Related Questions