Categories
JavaScript Answers TypeScript

How to access class member from a function in method class in TypeScript?

Spread the love

Sometimes, we want to access class member from a function in method class in TypeScript.

In this article, we’ll look at how to access class member from a function in method class in TypeScript.

How to access class member from a function in method class in TypeScript?

To access class member from a function in method class in TypeScript, we can use the this keyword.

For instance, we write:

class Foo {
  bar() {}
  baz() {
    this.bar()
  }
}

to call the bar method in the Foo by using this.bar as we did in the baz method.

Conclusion

To access class member from a function in method class in TypeScript, we can use the this keyword.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *