F
F
faleaksey2019-04-02 16:55:57
JavaScript
faleaksey, 2019-04-02 16:55:57

How to call a method of one class in another?

Hello! available Model:

class Model extends EventEmitter {
    constructor() {
    }

    getMethod() {
        console.log()
    }
}

which inherits EventEmitter.
EventEmitter also inherits View:
export default class View extends EventEmitter {
    _model: Model;
    _elements: Elements;

    constructor(model: any, elements: any) {
        super();
        this._model = model;
        this._elements = elements;
    }

    test() {
        console.log(this._model.getMethod());
    }
}

but when calling getMethod on the View in the test method, it says: Property 'getItems' does not exist on type 'Model'.
How to call the getMethod method in another class and what's the problem?
PS The code is not all! described the main points.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-04-02
@faleaksey

If this._model is true an object from Model, then there will be no problems. Your error says something else. It does not mention getMethod, but getItems. Look for the problem elsewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question