Consider the piece of code below.
The type of exports is function. But we can still have exports.hello
property. How is that possible??
const obj = {
exports: {}
}
obj.exports = () => {
console.log('invoked')
}
obj.exports.hello = () => {
console.log('hello() invoked')
}
var output = `type of obj => ${typeof obj} ####
type of obj.exports => ${typeof obj.exports} ####
obj.exporst.hello() is ${typeof obj.exports.hello}
`;
console.log(output);
The output is:
type of obj => object #### type of obj.exports => function #### obj.exporst.hello() is function
It is logical to have an exports
object (typeof 'object'
) and have functions like exports.hello
, exports.foo
, etc. But how can we have exports itself as function and then have properties of exports?