Express JS 'this' undefined after routing with app.get(..)

瘦欲@ 提交于 2019-11-29 03:56:54

You need to properly bind the function.

app.get('/v1/group', group.getAll);

only passes the getAll function as a handler, but the function itself has no concept of this. this is decided based on the context that is bound, or based on how the function is called. This blog post is useful for understanding how function context works.

app.get('/v1/group', group.getAll.bind(group));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!