D
D
Dmitry Kuznetsov2020-07-08 15:24:42
JavaScript
Dmitry Kuznetsov, 2020-07-08 15:24:42

How to call a method from another class in JS?

Good day. Faced one problem (not so selenium in JS) - I created 2 classes in two different files. In one of them, you need to call a method of another class. But no matter how I called (as I expected) - I can not call. He writes, they say:

(node:1240) UnhandledPromiseRejectionWarning: ReferenceError: ParserFile is not defined

Please tell me how to deal with this.

Actually code:
CLI.js

const ParseFile = require("./ParseFile");

class CLI {

  constructor() {
    (async () => {
      // Что то делает

      if (response.fileNew) {
        ParserFile.parseFile(response.fileNew);
      }

      if (response.fileOld) {
        ParserFile.parseFile(response.fileOld);
      }
    })();
  }
}

const cli = new CLI();


Cli.js main class. In the constructor, you need to call methods from the ParseFile.js class
ParseFile.js

export class ParserFile {
  parseFile(file) {
    // Что то выполняет
  }
}

const parserfile = new ParserFile();



Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-07-08
@dima9595

Read the documentation about static class methods (what you are currently calling), instantiation, and regular class methods.
Without documentation in any way, otherwise it's easier to pay someone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question