JavaScript closing function

<! DOCTYPE HTML > 
< HTML lang = "EN" > 
< head > 
    < Meta charset = "UTF-. 8" > 
    < title > enclosing function </ title > 
    < Script > 
        
        / * 
        function myAlert () { 
            Alert ( 'the Hello World ') 
        } 
        myAlert (); 
        * / 
        // first the wording: 
        // use parentheses wrapper function 
        ( function () { 
            iNum01 =  ' the Hello World ' ;
            Alert (iNum01); 
        }) (); 

        // second wording: 
        // function before adding! 
        ! function () { 
            iNum01 =  ' Hello wooooooorld ' ; 
            Alert (iNum01) 
        } (); 

        // third wording: 
        // added ~ function before 
        ~ function () { 
            iNum01 =  ' Hello wooooooorld aaaaaaagain ' ; 
            Alert (iNum01) 
        } (); 

        / * 

        benefits enclosing function: 
            closing function can create a separate space, variables and functions which are not defined It will affect the outside through the variables and functions of the same name, to avoid naming conflicts. when references js file, to avoid conflicts.
            Similar closures, private methods. 

            Iterative version used when more closed function, while unnecessary impact on the existing functionality 

        * / 

    </ Script > 

</ head > 
< body > 
    
</ body > 
</ HTML >

 

Guess you like

Origin www.cnblogs.com/jrri/p/11347410.html