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)
    

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

  • 相关阅读:
    eclipse lua
    eclipse新建python项Project interpreter not specified
    Laravel Debugbar
    Java中枚举类型简单学习
    SG函数题目
    关于解决博弈论问题的SG函数
    三种典型的博弈论问题
    Java I/O 对象序列化
    Java I/O 文件加锁,压缩
    Java I/O NIO学习
  • 原文地址:https://www.cnblogs.com/yiyitong/p/9401827.html
Copyright © 2011-2022 走看看