Correct async function export in node.js

前端 未结 2 1627
自闭症患者
自闭症患者 2020-12-24 00:48

I had my custom module with following code:

module.exports.PrintNearestStore = async function PrintNearestStore(session, lat, lon) {
...
}

2条回答
  •  清酒与你
    2020-12-24 01:18

    Error with first case: PrintNearestStore - Function expression, so this name not available outside.

    error with second case: using variable, instead Function declaration. In this case, declaration of variable PrintNearestStore are hoisted, so, you can use this name before line var PrintNearestStore = ..., but in this case value would be undefined.

    So, simplest solution change second variant like this:

    module.exports.PrintNearestStore = PrintNearestStore;
    
    async function PrintNearestStore(session, lat, lon) {
    
    }
    

提交回复
热议问题