文件:MainApp.js
var reqHandler = reqire('HTTPRequestPostHandler')..
...
...
var httpRequestHandler = new reqHandler();
app.post('/', httpRequestHandler.handleRootPost);
Run Code Online (Sandbox Code Playgroud)
文件:HTTPRequestPostHandler.js
HTTPRequestPostHandler =function(){
this.someVar = value;
}
HTTPRequestPostHandler.prototype.handleRootPost{
console.log(this.someVar) //Error -> this.someVar is undefined.
}
Run Code Online (Sandbox Code Playgroud)
我有这两个文件.MainApp.js是express配置的地方,每个端点的各种处理程序,例如'/'.
但是当发出post请求并调用请求处理程序(HTTPRequestPostHandler.prototype.handleRootPost)时,访问变量this.someVar时出现未定义的错误.
为什么会这样呢?我在这做错了什么.