1
我試圖理解快遞JS來源,這就是快遞出口無法理解這種快速JS源代碼片段
module.exports = createApplication;
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;
}
我感到困惑這段代碼
var app = function(req, res, next) {
app.handle(req, res, next);
};
主模塊變量app
同時在函數內部分配和使用。這如何工作?其他地方沒有定義app
。找到真正的來源here。
哦,是的。現在有道理。謝謝! –