JavaScript curly braces with no function or json

后端 未结 6 824
别那么骄傲
别那么骄傲 2020-12-06 16:16

Just opened a client\'s javascript file and the first lines are along the lines of this:

{
    var s_account=\"blog\";
}

Which I don\'t get

6条回答
  •  余生分开走
    2020-12-06 17:18

    The only logical reason to do something like this, in my mind, is as an organizational technique.

    function banana(){
        // private members
        {
            var foo = "foo",
                bar = "bar",
                baz = "baz";
    
            function bux(){
                console.log("bux");
            }
        }
    
        // public members
    
        this.fin = "fin";
        this.fang = "fang";
        this.foom = "foom";
    
        this.shamalamadingdong = function(){
            bux();
        };
    }
    

    Also, most IDEs will allow you to collapse that "private members" block and get it out of your way.

提交回复
热议问题