跳到主要内容
CNode

请问express这段源码是什么意思,特别是这个app的hanlde方法init哪里来的恩

问答
HHirayClay发布于 11 年前最后回复 11 年前
252650
var EventEmitter = require('events').EventEmitter;
var mixin = require('merge-descriptors');
var proto = require('./application');
var Route = require('./router/route');
var Router = require('./router');
var req = require('./request');
var res = require('./response');

/**
 * Expose `createApplication()`.
 */

exports = module.exports = createApplication;

/**
 * Create an express application.
 *
 * @return {Function}
 * @api public
 */

function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };

  mixin(app, EventEmitter.prototype, false);
  mixin(app, proto, false);

  app.request = { __proto__: req, app: app };
  app.response = { __proto__: res, app: app };
  app.init();
  return app;
}
查看回复

回复 (2)

H
HirayClay#211 年前

谢谢你,虽然很简洁,懂了

3
3went2#111 年前

mixin(app, proto, false);

参与回复

登录后即可参与回复。登录