node.js在函数类对象

时间:2017-08-03 18:00:16

标签: node.js

我有非常好的js背景,但我是node.js的新手 我不明白为什么简单的类对象函数没有调用

    function functions () {

        function test () {
            console.log("function ok");

            function test2 () {
                console.log("function inside function is ok");
            }
            return {
                test2 : test2
            };  
        }

        return {
            test : test
        };

    }

var test_function = new functions();
functions.test.test2();

我收到错误

TypeError: Cannot read property 'test2' of undefined

感谢

2 个答案:

答案 0 :(得分:1)

尝试拨打test_function.test().test2()。您需要先调用test(),然后才能调用test2()。另外,在您的示例中,您正确地调用了functions()并将其分配给test_function,但之后您没有对其执行任何操作。

答案 1 :(得分:0)

这样称呼它:

var test_function = new functions();
test_function.test().test2();
相关问题