简体   繁体   中英

_http_server.js - no request('events') yet .emit() && .on() how?

_http_server.js on github at /nodejs/node/blob/master/lib/_http_server.js uses the .emit() Method 14 times, plus it uses the .on() Method 11 times.

I am confused because I believe this method comes from request('events') in Node.js. I searched for a such in the entire file and this line has been commented out from Line 113 to Line 130. I can find no other way for the .emit() and .on() Methods to be used.

Could anyone explain how it is possible to use both the .emit() and the .on() without request('events')?

_http_server.js uses EventEmitter (what you get from require('events') ) through inheritance .

This is why _http_server.js is able to use EventEmitter methods even though you don't see require('events') in that file: the classes it depends on ultimately depend on EventEmitter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM