문제

The code below is from connect which is a popular module in nodejs.

function createServer() {
  function app(req, res, next){ app.handle(req, res, next); }
  merge(app, proto);
  merge(app, EventEmitter.prototype);
  app.route = '/';
  app.stack = [];
  return app;
}

I'm thinking for a long time, but I don't know how the function app executes. Is anyone familiar with the code ? Please tell me how it works. Thank you!

도움이 되었습니까?

해결책

There is likely more to that code later on.

According to this blog,

The code above uses utils.merge to give app all the functionality of the Connect http server prototype. This includes the .use, .handle, and .listen methods.

The app also merges EventEmitter from the node.js events library. EventEmitter is where app gets app.on and app.emit from.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top