zoukankan      html  css  js  c++  java
  • 函数声明、函数表达式及函数立即执行

    
    
    函数声明:
    function a() {}

    函数表达式:
    var a = function () {}

    代码示例:

    a();  // 1,函数声明提升
    function a(){
      console.log(1);
    }
    a();  // 1
    var a = function(){
      console.log(2);
    }
    a();  // 2,函数表达式不会提升,覆盖函数声明
    

      

    a(); // 1,函数声明提升
    var a = function(){
      console.log(2);
    }
    a(); // 2,函数表达式覆盖函数声明
    function a(){
      console.log(1);
    }
    a(); // 2,函数声明提升后先于函数表达式声明,因此函数表达式会覆盖函数声明
    

      

    函数立即执行

    (function(a){
      console.log(a);  //使用()运算符
    })(1);
      
    (function(a){
      console.log(a);  //使用()运算符
    }(1));
      
    !function(a){
      console.log(a);  //使用!运算符
    }(1);
      
    +function(a){
      console.log(a);  //使用+运算符
    }(1);
      
    -function(a){
      console.log(a);  //使用-运算符
    }(1);
      
    var fn=function(a){
      console.log(a);  //使用=运算符,函数表达式立即执行
    }(1)
    

     ()、!、+、-、=等运算符,都将函数声明转换成函数表达式 

  • 相关阅读:
    cell list of blocks physical read等待事件
    cell manager discovering disks等待事件
    OOP
    静态网页与动态网页的区别
    一个HTTP请求的详细过程
    PING 确认网络连接情况
    软件开发模型
    搭建网站的全套流程
    Design Diagram
    网络基础
  • 原文地址:https://www.cnblogs.com/yiyitong/p/9401827.html
Copyright © 2011-2022 走看看