In node.js “request.on” what is it this “.on”

前端 未结 3 662
抹茶落季
抹茶落季 2020-12-24 07:40

I\'m new in node.js and java script, i cant find meaning of this \".on\" keyword. when i change it with another word code failed.

var req = http.get(\"http:/         


        
3条回答
  •  无人及你
    2020-12-24 07:54

    The on method binds an event to a object.

    It is a way to express your intent if there is something happening (data sent or error in your case) , then execute the function added as a parameter. This style of programming is called Event-driven programming. You might want to look it up in the Wikipedia

    In node.js, there is a class called EventEmitter that provides you with all the code that you need for basic events if you decide to use them in your own code (which I would strongly recommend in the case of node.js). Docs for node.js EventEmitter are here

提交回复
热议问题