I’ve been using node.js for some time now and I realized that require is a function, and an object, or so it seems. You can do the following:
require('someModule')
let a = require.cache //not undefined
I’ve been trying to do this myself but I can’t figure out how. These are the things I tried:
function a() {
console.log('a')
}
let a = {test: 1}
//throws cannot declare variable twice
And reversed it
let a = {test:1}
function a() {
console.log('a')
}
//still throws
I even tried adding a toFunction method to a class, making an instance of it, and trying to call on the instance, which I hoped would work like toString(), but it still said a is not a function.
How can I do this myself? It’s probably super simple but I couldn’t find it anywhere when researching.