I have the following code
module.exports = {
_renderIndex: async (req, res) => {
console.dir("test");
},
index: async (req, res) => {
this._renderIndex(req, res, {});
}
};
Unfortunately, when I run the function index, I get the error this._renderIndex is not a function. Can someone please tell me why?
CodePudding user response:
The object you are trying to reference by this
doesn't exist yet
Try just defining it first and not using this
const _renderIndex = async (req, res) => {
console.dir("test");
}
module.exports = {
_renderIndex,
index: async (req, res) => {
_renderIndex(req, res, {});
}
};
CodePudding user response:
render.js
const _renderIndex = async (req, res) => {
console.dir("test");
}
const index=(){}
module.exports ={renderIndex:_renderIndex,index:index};
in another file
import {renderIndex,index} from 'render.js'