2015-02-23 60 views

回答

0

app是與function app(....第一行定義。

然而,appmerge膨脹-ing經由管線merge(app,proto)使用util-mergeproto模塊。

另請注意合併EventEmitter.prototype,因爲這也很重要。

查看與connect.js位於同一目錄中的proto.js文件,您將看到導出的完整app對象。

function createServer() { 
    function app(req, res, next){ app.handle(req, res, next); } 
    merge(app, proto); 
    merge(app, EventEmitter.prototype); 
    app.route = '/'; 
    app.stack = []; 
    return app; 
} 
+0

謝謝,我想用'proto.app'是在這條線更加清晰。 – why 2015-02-23 14:08:50

0
function app(req, res, next){ app.handle(req, res, next); } 
//  ^^^     ^^^ 

它定義在那裏。 將handle函數添加到app以後(在proto.js文件中定義),使用merge(app, proto)

這裏的代碼做什麼簡單的例子:

function dog() { 
    dog.bark(); 
}; 

dog.bark = function() { 
    console.log('Woof!'); 
}; 

dog(); 
相關問題