I couldn’t find this answer on Google because ‘on’ is such a common word.
In this node.js example:
conn.on('close', function() {
var pos = connections.indexOf(conn);
if (pos >= 0) {
connections.splice(pos, 1);
}
});
There is a .on method(?). What it does? It is a JavaScript method? Or it is something you only find in node? I’m kind of confused because I think I saw something like .on on jQuery. Is it similar to the jQuery .live event handler?
Can anyone explain this to me?
It is a method from Node’s EventEmitter class:
https://nodejs.org/docs/latest/api/events.html#events_emitter_on_eventname_listener