zoukankan      html  css  js  c++  java
  • 函数

    函数声明

      function  test1( ){console.log(11111)}

    函数表达式

      var  test2  =  function  ( ){console.log(2222)}

    函数参数

      function  test(a, b){

        // 相当于隐式的在函数内定义a变量和b变量

        // arguments 实参列表 [11, 3, 4]

        // test.length 形参数量

      }

      test(11, 3, 4)

    有实参的形参和arguments相映射

      function  sum(a, b){

        // a有实参,所以和arguments相映射

        a  =  2;

        console.log(arguments[0])  // 2

        arguments[0]  =  3;

        console.log(a)  // 3

        // b没有实参,所以不能和arguments相映射

        b  =  2;

        console.log(arguments[1])  // undefined

      }  

      sum(1)

    闭包:当内部函数被保存到外部时,将会生成闭包,闭包会导致原有作用域链不释放,造成内存泄漏

      

    立即执行函数:此类函数没有声明,在一次执行过后即释放。适合做初始化工作

      只用函数表达式才能被执行负号执行

      (function ( ){ } ( ))

      (function ( ) { })( )

      function  test  ( ){console.log('不能被执行')}( )

      var  test  =  function  ( ) {console.log('可以被执行')})( )

      console.log(test)  // undefined

      + function  test ( ){console.log('可以被执行')}( )

      console.log(test)  // 报错

      - function  test ( ){console.log('可以被执行')}( )

      console.log(test)  // 报错

      ! function  test ( ){console.log('可以被执行')}( )

       console.log(test)  // 报错

    arguments.callee

      function  test ( ){

        console.log(arguments.callee)  // 输出test函数体

        console.log(arguments.callee  ==  test)  // true

      }

      test( )

      实例:

      var  num  =  (function (n){

        if(n  ==  1){

          return  1;

        }

        return  n  *  arguments.callee(n  -  1)

      }(100))

    fun.caller

      function  test ( ){

        demo( );

      }

      function  demo ( ){

        console.log(demo.caller)  // 输出test函数体

      }

     

  • 相关阅读:
    netcore使用IdentityServer在nginx下502错误的解决
    更新到.netcore3.0后找不到dotnet-ef的解决办法
    openssh-win64 on windows2016 ssh pub key config
    405 Method Not Allowed error with PUT or DELETE Request on IIS Server
    minikube windows hyperx填坑记
    angular当router使用userhash:false时路由404问题
    内网gitlab11.2升级至11.4.5
    Angular7上手体验
    动态规划之背包问题
    Union-Find算法详解
  • 原文地址:https://www.cnblogs.com/cuishuangshuang/p/13228145.html
Copyright © 2011-2022 走看看