1

I have 2 files.

1) accountService.js

export class Http {

forgotPassword(email) {
console.log(email)
  }
}

2) forgot-password.js

import {Http} from '../services/accountService'

 export class ForgotPassword {

 sendCode(email) {
    Http.forgotPassword(email)
  }
}

When I'm trying to call Http.forgotPassword(email) in forgot-password.js there is console error, that says Http.forgotPassword in not a function.

V. Aliosha
  • 142
  • 1
  • 13

2 Answers2

3

forgotPassword method needs to be static if you want to call it like that;

static forgotPassword(email) {
    console.log(email)
}
eko
  • 37,528
  • 9
  • 64
  • 91
1

In your example, forgotPassword is an instance method. You will need to do

export class ForgotPassword {
  constructor() {
    this.http = new Http
  }
  sendCode(email) {
    this.http.forgotPassword(email)
  }
}

However, if those files you've shown were the whole code, you should neither use classes nor export objects with methods. Just export the functions.

Bergi
  • 572,313
  • 128
  • 898
  • 1,281