3
I was left with a question concerning the structure of the Express.
How Express can be invoked, as in express()
, but can also have in its structure access to the Router property, for example?
I don’t know if my doubt was clear, so I’ll try to illustrate. To create a structure with access to a name method Router
, for example, just create an object and set a property for it with name Router
and to give it a function, example:
var express = {
Router: () => { console.log("Acessou o router"); }
};
In the example above, I could access the property Router
easily, as in express.Router()
.
The problem is that in the above form it would not be possible to invoke the Express object as in express()
, since it is an object. If I try to do as in the example below, it gives error:
var express = {
(): () => { console.log("Iniciou o express"); },
Router: () => { console.log("Acessou o Router"); }
};
I don’t need to understand specifically how Express does, but I would just like to understand how this would be possible, since in my view it would not be possible for an object to work with direct function calls.
Related: https://answall.com/q/474549/112052 (explains that every function is also an object and therefore may have properties)
– hkotsubo