in es6 there you can define a module of functions like this
export default {
foo() { console.log('foo') },
bar() { console.log('bar') },
baz() { foo(); bar() }
}
the above seems to be valid code, but if I call baz()
it throws an error:
ReferenceError: foo is not defined
How do you call foo
from another function? in this case baz
Edit
Here's the code that actually doesn't work. I have simplified the code so it's only the core as needed
const tokenManager = {
revokeToken(headers) {
...
},
expireToken(headers) {
...
},
verifyToken(req, res, next) {
jwt.verify(... => {
if (err) {
expireToken(req.headers)
}
})
}
}
export default tokenManager
and the error is
expireToken(req.headers);
^
ReferenceError: expireToken is not defined
Edit 2
I just tried adding tokenManager
before expireToken
and it finally works