Javascript 为什么可以';t我在Express'上使用Function.prototype.apply;应用程序使用?

Javascript 为什么可以';t我在Express'上使用Function.prototype.apply;应用程序使用?,javascript,express,Javascript,Express,我刚刚注意到,例如app.use.apply(null,['/',f=>f]) 将抛出一个打字错误 TypeError: Cannot read property 'lazyrouter' of null at use (node_modules/express/lib/application.js:214:7) 假设我的express app实例已正确设置,我做错了什么?我想这是合适的结婚方式应用程序。使用([路径],cb) apply()将更改函数中的this。对于应用程序,use(

我刚刚注意到,例如
app.use.apply(null,['/',f=>f])

将抛出一个打字错误

 TypeError: Cannot read property 'lazyrouter' of null
  at use (node_modules/express/lib/application.js:214:7)
假设我的express app实例已正确设置,我做错了什么?我想这是合适的结婚方式<代码>应用程序。使用([路径],cb)

apply()将更改函数中的
this
。对于
应用程序,use()
this直接指向
应用程序的实例,但是您将其设置为
null
,并且
null
上没有附加
use
函数属性,因此会引发错误。

应用()
将更改函数中的
this
。对于
应用程序,use()
this
直接指向
应用程序的实例,但您将其设置为
null
,并且
null
上没有附加
use
函数属性,因此会抛出一个错误。

当函数作为对象的方法调用时,如在
应用程序中。使用([path],cb)
,在函数调用中,
this
关键字会绑定到对象。
apply
的第一个参数是要提供的
this
绑定,因此需要编写
app.use.apply(app,['/',f=>f])

当函数作为对象的方法调用时,如在
应用程序中。使用([path],cb)
,在函数调用中,将
this
关键字绑定到对象。
apply
的第一个参数是要提供的
this
绑定,因此需要编写
app.use.apply(app,['/',f=>f])