0

I have some module file:

const dbModule = module.exports = {
  setBase: (apiKey, base) => new Airtable({ apiKey }).base(base),
  base: dbModule.setBase('', '')
}

But I get an error message during compile: variable 'dbModule' used before its declaration.

So how can I define base method to call setBase ?

2 Answers 2

1

Rather than declare the variable you are exporting as one step, you could separate it out into multiple steps:

const dbModule = {
  setBase: (apiKey, base) => ....
};

dbModule.base = dbModule.setBase('', '');

module.exports = dbModule;
Sign up to request clarification or add additional context in comments.

Comments

0

I'm assuming you have defined dbModule elsewhere in your code.

class dbModule {

  setBase() {
  ....
  }
  base() {
    setBase();
  }
};
module.exports = new dbModule();

This class based programming makes sure that each of your functions belong to the class object and can access one another.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.