Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrow Functions não são herdadas #2

Open
bernborgess opened this issue Feb 19, 2023 · 0 comments
Open

Arrow Functions não são herdadas #2

bernborgess opened this issue Feb 19, 2023 · 0 comments

Comments

@bernborgess
Copy link

Arrow Functions não são herdadas

Existem vários métodos inicializado com uma arrow function, a inicialização é feita pelo construtor:

export abstract class DioAccount {
  ...
  getBalance = (): void => {
    console.log(this.balance)
  }
}

O campo não termina na cadeia de protótipos, portanto não é herdado e você não pode chamá-lo por meio de super.

export class CompanyAccount extends DioAccount {
 ...
  super.getBalance()

>> [ERROR] 20:14:18 TypeError: (intermediate value).getBalance is not a function

Sugiro escrever métodos normais:

  getBalance (): void {
    console.log(this.balance)
  }

Assim é possivel usá-los nos exercícios:

export class CompanyAccount extends DioAccount {
 ...
  super.getBalance()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant