我如何monkeypatch快速查看查找?

我试图重写快速查看查找function,但无法设法做到这一点。 目标是能够在多个目录中查找模板。

我想要做的是,在bootstrap.js

 function bootstrap(express) { var originalLookup = express.View.prototype.lookup; express.View.prototype.lookup = function(path) { console.log('Requested for', path); return originalLookup(path); }; }; module.exports = bootstrap; 

我的app.js代码是:

 var express = require('express'), routes = require('./routes'), bootstrap = require('./bootstrap'), app = module.exports = express.createServer(); // Configuration require('./config/environment.js')(app, express); // Bootstrap bootstrap(express); // Routes require('./config/routes.js')(app); // Start app.listen(3000); 

在我的bootstrap.js代码中,express.View.prototype.lookup是未定义的。 我不明白为什么。 我做错了什么?

我刚刚开始与node.js和“高级”Javascript。 我不得不承认我有点迷路了

谢谢。

在当前版本(2.5.9)中,不是View.prototype.lookup,它只是View.lookup。

 ~: ) node > require('express').View { [Function: View] register: [Function], compile: [Function], lookup: [Function] } > require('express').View.lookup [Function]