Yes, that's possible as long as there is no other builtin properties with same name.
io.sockets.on('connection', function (client) {
client.on('data', function (somedata) {
// if not client['data'] you might need to have a check here like this
client['data'] = somedata;
});
});
I'd suggest another way, but with ECMAScript 6 weak maps
var wm = new WeakMap();
io.sockets.on('connection', function (client) {
client.on('data', function (somedata) {
wm.set(client, somedata);
// if you want to get the data
// wm.get(client);
});
client.on('disconnect', function() {
wm.delete(client);
});
});
client
? You're missing a bunch of context here for anyone to be able to answer. – Winkelman