我在快递应用程序中的以下行设置了一个断点。
app.get('/api/post/:id', api.post);
当我进入该功能时,它会转到:
/**
* Delegate `.VERB(...)` calls to `.route(VERB, ...)`.
*/
methods.forEach(function(method){
app[method] = function(path){
if (1 == arguments.length) return this.routes.lookup(method, path);
var args = [method].concat(toArray(arguments));
if (!this.__usedRouter) this.use(this.router);
return this.routes._route.apply(this.routes, args);
}
});
任何人都可以解释发生了什么吗?它是如何以及为何直接针对这段代码?
答案 0 :(得分:0)
已发布的代码位是app.get
函数的内容声明。
methods
将是一组动词(get
,post
,put
等),并且每个动词都在app
上声明为函数。
我认为你真正感兴趣的是api.post
函数。要检查您是否必须在该函数中放置断点,或者单步执行此行apply
上的this.routes._route.apply(this.routes, args);
以查看接下来会发生什么。