【发布时间】:2017-05-06 18:56:03
【问题描述】:
我刚刚开始使用 typescript 而不是 javascript 来编写我的 node.js 应用程序。我有点困惑。
我有这段代码可以启动一个快速服务器
import * as express from 'express';
class Server {
static expressApp: express.Express;
static PORT: number = 3000;
public static startServer():void {
this.expressApp = express();
console.log(this.PORT);
this.expressApp.listen(this.PORT, this.serverStartedCallback)
}
private static serverStartedCallback():void {
console.log("Server is listening on port " + this.PORT);
}
}
Server.startServer();
我可以在startSever()中得到PORT变量的值。
但在回调 serverStarted() 中,this.PORT 变量是 undefined。
有人可以详细说明这是为什么吗?
【问题讨论】:
-
this.constructor.serverStartedCallback
标签: node.js express typescript