Your result gave: [['this']['is']['a']['namespace']], not the desired structure I was hoping for ...
I'm setting up a node server using socket.io. On the node server, I use the following namespace:
Code:
GLOBAL = {
dialog: {
settings: function() {},
profile: function() {}
}
} // With much, much more ...
With socket.io you invoke a function of the backend, from the front end.
Front end:
Code:
io.emit('getSettings', {}, function() {});
These functions are defined on the backend like follows:
Code:
io.on('getProfile', function() {
// Get profile from the db
});
But this way, I have to define many different functions, one af the other. In other words, one big unstructured mess Therefore I have put the content of these functions in a namespace (consistent with the namespace of the application itself)
Like the following:
Front end:
Code:
io.emit('message', {'method: 'this is a namespace'}, function() {});
Back end:
Code:
io.on('message', function(params) {
Namespace to the desired function ...
});
This way you only have to define a funcion once, with one method called 'message', and then in the body 'namespace' to a particular function.
Bookmarks