In Node.js, what's “on”?

后端 未结 3 1435
长情又很酷
长情又很酷 2021-02-18 23:20

In official doc, there is some sample code:

var req = http.request(options, function(res) {
  console.log(\'STATUS: \' + res.statusCode);
  console.log(\'HEADERS         


        
相关标签:
3条回答
  • 2021-02-18 23:27

    The documentation for Events implies they're two aliases for the same function.

    0 讨论(0)
  • 2021-02-18 23:31

    Both on and addListener are aliases for the same function.

    0 讨论(0)
  • 2021-02-18 23:36

    As far as I'm aware, it's no different than addListener. There is some documentation on the event here: http://nodejs.org/docs/latest/api/events.html#emitter.on Both on and addListener are documented under the same heading. They have the same effect;

    server.on('connection', function(stream) {
        console.log('someone connected!');
    });
    
    server.addListener('connection', function(stream) {
        console.log('someone connected!');
    });
    
    0 讨论(0)
提交回复
热议问题