Frage

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!

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top