I'm new to node.js, but wrote Javascript for many years, and I stumbled upon a pattern, that I don't understand: A Flag that sets a modifier on the object.
For instance here socket.io docs:
Flag: 'broadcast'
Sets a modifier for a subsequent event emission that the event data will only be broadcast to every sockets but the sender.
var io = require('socket.io')();
io.on('connection', function(socket){
socket.broadcast.emit('an event', { some: 'data' }); // everyone gets it but the sender
});
Here socket is an object, and broadcast is a property of that object, while socket.broadcast is that same object with a modifier set ?!
How is it possible that accessing the property of an objet returns the object itself ?
Is this a feature of Javascript that I ignored for years? Or is this some new feature of ES6 that I'm not aware of ? Or is this a coding pattern specific to node ?
And how does it work / is it achieved ?
Edit: even though the other question is about the same exerpt in the docs, it is very different. My question is about the background in Javascript, while the other one is about the wording in the docs. The answers also are very different for this reason.