2015-02-23 61 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(); 
相关问题