Trong official doc, có một số mẫu mã:Trong Node.js, "on" là gì?
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
tôi có thể hiểu nó trừ một phần: là những gì on
trong res.on
? Sự khác nhau giữa nó và addListener
là gì?