function createApplication() { var app = function(req, res, next) { app.handle(req, res, next); }; mixin(app, EventEmitter.prototype, false); mixin(app, proto, false); // expose the prototype that will get set on requests app.request = Object.create(req, { app: { configurable: true, enumerable: true, writable: true, value: app } }) // expose the prototype that will get set on responses app.response = Object.create(res, { app: { configurable: true, enumerable: true, writable: true, value: app } }) app.init(); return app;}代碼Github頁面地址點擊這里
expressjs 源碼 為什么用mixin拓展app, 而不是像下面用Object.create
一只名叫tom的貓
2019-03-05 13:15:03