I
I
ivandao2019-11-18 13:56:20
JavaScript
ivandao, 2019-11-18 13:56:20

How to call a function in an object?

How to call a function in this way?

module.exports = { 
  func1: ()=>{...},
  func2: ()=>{
    ...
    func1()  // Как правильно вызывать эту функцию?
    ...
  }
}

I did require the module to myself, but it's somehow dumb.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2019-11-18
@ivandao

Option 1: save the object, then throw it into exports

const object = { 
  func1: ()=>{...},
  func2: ()=>{
    ...
    object.func1();
    ...
  }
};
module.exports = object;

Option 2: use prototypes and this pointer
module.exports = { 
  func1() {...},
  func2() {
    ...
    this.func1();
    ...
  }
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question