[英]How to have multiple routes use the same route function in express.js
[英]How is it that in express.js, a function appears to have properties?
摘自: https : //github.com/strongloop/express/blob/master/lib/express.js
function createApplication() {
var app = function(req, res, next) { // app here is a function
app.handle(req, res, next); // how is it that app can have properties? is this recursive?
};
mixin(app, proto);
mixin(app, EventEmitter.prototype);
app.request = { __proto__: req, app: app }; // property declaration
app.response = { __proto__: res, app: app }; // property declaration again
app.init();
return app;
}
合法的先生,请您关注主要来源链接!
JavaScript中的所有非基本体都是对象。 这包括函数,数组,RegExps,日期等。
好的,这对我来说令人满意地回答了所有问题: http : //jsfiddle.net/geoyws/4ebv4pbv/
var x = function () {
alert(1); // alerts 1
x.wtf = 2;
x.ftw = 3;
return x.ftw;
}
alert(x()); // alerts 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.