Node.js:在同一模块中从另一个调用一个导出函数

and*_*urd 6 module node.js

我正在编写一个node.js模块,它导出两个函数,我想从另一个函数调用一个函数,但我看到一个未定义的引用错误.

有这样的模式吗?我只是创建一个私有函数并将其包装好吗?

这是一些示例代码:

(function() {
    "use strict";

    module.exports = function (params) {
        return {
            funcA: function() {
                console.log('funcA');
            },
            funcB: function() {
                funcA(); // ReferenceError: funcA is not defined
            }
        }
    }
}());
Run Code Online (Sandbox Code Playgroud)

Vad*_*hev 8

我喜欢这样:

(function() {
    "use strict";

    module.exports = function (params) {
        var methods = {};

        methods.funcA = function() {
            console.log('funcA');
        };

        methods.funcB = function() {
            methods.funcA();
        };

        return methods;
    };
}());
Run Code Online (Sandbox Code Playgroud)