CNode

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

问答
HHirayClay发布于11 年前最后回复11 年前2 回复5235 浏览0 收藏
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)

3
3went2#1·11 年前

mixin(app, proto, false);

H
HirayClay#2·11 年前

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

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