【发布时间】:2015-05-17 05:31:21
【问题描述】:
我正在为 express 创建一个中间件模块,但在“app.use”中使用时似乎无法让对象属性传递
function test (mytest) {
this.mytest = mytest;
};
test.prototype.showTest = function (req, res, next) {
console.log(this.mytest);
next();
};
var s = new test('foo');
router.post('/login', s.showTest, function (req, res) {
res.send('test');
});
此代码将输出“未定义”而不是“foo”。我怎样才能让它保留对象属性?
【问题讨论】:
-
s.showTest.bind(s)
标签: javascript node.js express middleware