Global functions in javascript

后端 未结 6 2212
攒了一身酷
攒了一身酷 2020-12-06 16:43

I\'m new to js and trying to understand global and private functions. I understand global and local variables. But if I have an html named test.html and a 2 js

6条回答
  •  长情又很酷
    2020-12-06 17:03

    var SomeName = function() {
    
        var function1 = function (number) {
            return number+1;
        }
    
        var anotherFunction = function (number) {
            return number+2;
        }
    
        return {
            function1: function (number) {
                return function1(number);
            },
            function2: function (number) {
                return anotherFunction(number);
            }
        }
    }();
    

    calling

    console.log(SomeName.function1(1)); //logs 2

    console.log(SomeName.function2(1)); //logs 3

提交回复
热议问题