I am attempting to make something simple using Node.js and Express. I have a rails background and I am emulating the RESTful structure Rails apps use. For my controllers (or routes w/e), I want to have something like this:
// routes/users.js
exports.new = function(req, res) {
res.render('users/new', { title: 'New User' }
};
exports.show = function(req, res) {
res.render('users/show', { title: 'View User' }
};
I am wondering, is it okay to do exports.new = .... I know that new is a keyword in Javascript, so I wont to make sure there wont be any unintended consequences.
You probably won’t run into any problems with this. This is an issue on older browsers (look at “reserved words as property names”), but I doubt V8 will ever have trouble with this, unless you plan on serving controllers.
If you really want to play it safe though, you could always pass them as strings to exports like exports[“new”], or use coffeescript – it automatically turns plain keys that are reserved words into strings.