zoukankan      html  css  js  c++  java
  • JavaScript 封闭函数

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>封闭函数</title>
        <script>
            
            /*
            function myAlert(){
                alert('Hello World')
            }
            myAlert();
            */
            // 第一中写法:
            //使用小括号包裹函数
            (function(){
                iNum01 = 'Hello World';
                alert(iNum01);
            })();
    
            // 第二种写法:
            // 函数前加 !
            !function(){
                iNum01 = 'hello wooooooorld';
                alert(iNum01)
            }();
    
            // 第三种写法:
            // 函数前加 ~
            ~function(){
                iNum01 = 'hello wooooooorld aaaaaaagain';
                alert(iNum01)
            }();
    
            /*
    
            封闭函数的好处:
                封闭函数可以创造一个独立的空间,里面定义的变量和函数不会影响外面的通同名变量和函数 , 可避免命名冲突 . 在引用js文件的时候,避免冲突.
                类似于闭包 , 私有方法.
    
                迭代版本时候更多使用封闭函数,一边对现有功能产生不必要影响
    
            */
    
        </script>
    
    </head>
    <body>
        
    </body>
    </html>
  • 相关阅读:
    Http请求头与响应头
    获取ip位置方法
    简单的Http Server实现
    HTTP
    long、int与byte数组之间的相互转换
    GlusterFS简单配置
    创建线程池
    网络编程socket
    面向对象-进阶篇
    面向对象-初级篇
  • 原文地址:https://www.cnblogs.com/jrri/p/11347410.html
Copyright © 2011-2022 走看看