The previous answer is incomplete.
The 1st example adds methods ONLY TO THAT SPECIFIC INSTANCE of Client class.
The 2nd example adds methods to all the Class prototype.
This distinction is very important for some uses cases.
If for example the client that connects to a room has administrative privileges created by your logic, in onConnect's client instance you will add methods only to admin's user client otherwise in each admin method you will need to check if the client is admin or not (which would be ugly)
Sample:
application.isAdminUser = function(cParams) {
if (cParams.username == 'admin') {
return true;
} else {
return false;
}
}
/* bad - people can simulate clients */
application.onConnect = function(client, cParams) {
client.disconnectUser = function(userId) { application.myDisconnect(userId); };
client.allClientsMethod = function() { };
}
/* good */
application.onConnect = function(client, cParams) {
if(this.isAdminUser(cParams)) {
client.disconnectUser = function(userId) { application.myDisconnect(userId); };
}
// this following is applied to all connecting clients
client.allClientsMethod = function() { };
// and can be done also by:
// Client.prototype.allClientsMethod = function() { };
}
If you do not put the disonnectUser inside the if you can imagine a malicious person could forge a client that would allow him to disconnect any of your users.
I hope this helps.