Skip to content

Instantly share code, notes, and snippets.

@thatmarvin
Created March 18, 2013 18:48
Show Gist options
  • Save thatmarvin/5189720 to your computer and use it in GitHub Desktop.
Save thatmarvin/5189720 to your computer and use it in GitHub Desktop.
'use strict';
var express = require('express')
, app = module.exports = express.createServer();
// Configuration
app.configure(function () {
app.use(app.router);
});
function Controller(model) {
this.model = model;
}
Controller.prototype.find = function (req, res, next) {
res.send(typeof this);
}
var c = new Controller({});
// "this" is undefined in Express 2
app.get('/1', c.find);
// "this" is correctly returned as an object
app.get('/2', function (req, res, next) {
c.find(req, res, next);
});
// Start server
app.listen(3000, function () {
console.log('Express server listening on port %d in %s mode', app.address().port, app.settings.env);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment