Hi,
I'm struggling with a problem for quite some time and would be happy to finally find a solution. I use JS on the front and backend (Node).
I store all my functionallity for the backend in one global variable. This is partially true, but for the simplicity of this example, let's go with that 
GLOBAL = {
base: {
getTemplates: function() {
// Contruct a template object
},
otherFunction: function() {
// Do some other cool JS stuff
}
}
}
Ok, now I'm looking for a way to trigger a particular function on the backend, from the frontend. For the communication between front and back I use socket.io. Socket.io let you pass an object with values.
I was wondering if I could do something like this
var o = {
namespace: [base][getTemplates]
}
io.emit('request', o, function(templates){});
This way I hope to receive at the backend an object with a value which defines the exact places of the particular function on the backend and contruct the function on the backend like follows:
io.on('req', function( params) {
// Append the namespace to our GLOBAL variable to point the exact
// location of the function, namely GLOBAL.base.getTemplates() and
// return the result back to the frontend.
return GLOBAL[params.namespace]();
});
Can we solve this problem with something like JSON.stringify or ...
Any help is more than welcome!!!
Thanks in advance!!!
Christophe