Coffeescript 类变量未定义。。。尽管被定义了

Coffeescript 类变量未定义。。。尽管被定义了,coffeescript,node-postgres,Coffeescript,Node Postgres,我有一个名为RouteBinder的类,如下所示: class RouteBinder 构造函数:(@server,@pool)-> bindRoute:(名称,fn,method=“post”,useDb=true)-> @服务器[方法](“/api/accounts/v1/”+name,(req,res,next)-> client=await@pool.connect()如果使用数据库? 等待fn请求、res、next、客户端 如果使用数据库,请等待@pool.release()? )

我有一个名为RouteBinder的类,如下所示:

class RouteBinder
构造函数:(@server,@pool)->
bindRoute:(名称,fn,method=“post”,useDb=true)->
@服务器[方法](“/api/accounts/v1/”+name,(req,res,next)->
client=await@pool.connect()如果使用数据库?
等待fn请求、res、next、客户端
如果使用数据库,请等待@pool.release()?
)
我声明并这样称呼它:

binder=新的RouteBinder服务器,池
binder.bindRoute“login”,controllers.login
(池是节点postgres的池,在前面像这样声明和测试)

pool=新池
[...]
尝试
客户端=等待池。连接()
等待client.query“选择1=1”
抓住e
console.fatal“无法连接到数据库:#{e}”
返回
最后
如果是客户端,请尝试client.release()?
抓住e
console.fatal“无法释放客户端:#{e}”
返回
console.info“数据库正常!”
运行此操作时,我遇到以下错误:

02/14 18:44:34错误(节点:11855)未处理PromisejectionWarning:TypeError:无法读取未定义的属性“connect”
在_callee2$(/home/vi/[redact]\u accounts/main.js:136:38)
在tryCatch(/home/vi/[redact]\u accounts/node\u modules/registrator runtime/runtime.js:45:40)
在Generator.invoke[as _invoke](/home/vi/[redacted]_accounts/node_modules/registrator runtime/runtime.js:271:22)
在Generator.prototype.(匿名函数)[as next](/home/vi/[redact]\u accounts/node\u modules/registrator runtime/runtime.js:97:21)
在asyncGeneratorStep(/home/vi/[redact]\u accounts/node\u modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
下一步(/home/vi/[redact]\u accounts/node\u modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
at/home/vi/[redact]\u accounts/node\u modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
在新的承诺()
at/home/vi/[redact]\u accounts/node\u modules/@babel/runtime/helpers/asyncToGenerator.js:21:12
at/home/vi/[redated]_accounts/main.js:166:26
02/14 18:44:34错误(节点:11855)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:1)
02/14 18:44:34错误(节点:11855)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。
我用的是用巴贝尔编译的咖啡脚本。My.babelrc看起来像这样:

{
“预设”:[“@babel/env”],
“插件”:[
[“@babel/plugin转换运行时”,
{
“再生器”:正确
}
]
]
}

抱歉,如果这是一个新手问题,我仍在学习,希望能得到所有建议。

我发现了我的错误。
@pool
@server
都已定义,但是
@server[method]
的内联函数(处理程序)正在该函数的上下文中运行

解决方案是使用
.bind(@)
(或者
.bind(this)
,如果愿意的话)将其绑定到RouteBinder实例

bindRoute:(名称,fn,method=“post”,useDb=true)->
@服务器[方法](“/api/accounts/v1/”+name,((req,res,next)->
console.log“pool”、@pool
client=await@pool.connect()如果使用数据库?
等待fn请求、res、next、客户端
如果使用数据库,请等待@pool.release()?
).bind(@))