var a = 0;

b = 0;

function A(a) {

       A = function (b) {

       console.log(a + b++)

      }

console.log(a++)

}

A(1)

A(2)

JavaScript characteristic :
Closure mechanism : After closure creation , You can save the active object at the time of creation .
Self additive operator :++, When ++ As a suffix operator , call ++ The value of the expression of is the value of the self adding object before self adding .

It is explained here ++ Properties of operators .
var i = 0;
var eg = i++
console.log(i, eg) // 1 0

 

  First call A Time , Execution to console.log(a++) Time ,a Self adding has been completed , here a The value of is 2,a++ The value of is 1.

A(1)=1

  Second call A Time ,A Has been reassigned , Points to a new function reference ;

  Due to identifier A Is defined in the global scope , So it's reassigned inside the function , The reassigned function can also be accessed in the global scope .

  here , A closure is also created , This closure holds the active object of the creation environment .

  The active object :{ a: 2 }, meanwhile , According to the value passed in 2, determine b = 2,b++ The value is 3.

  Execution to console.log(a + b++), So output 4

A(2)=4

Technology
©2019-2020 Toolsou All rights reserved,
( Super detail )Eclipse Using tutorials —— use Eclipse Create first HelloWorld! Database operation 5 code implementation mysql Addition, deletion, modification and query of database What can MCU do , Do you have any interesting works made by MCU or open source hardware Go to the interview after reading this , Steady over ~~ Single linked list of primary data structure (C Language implementation )SQL Comprehensive questions Employee unit comprehensive questions Python Implementation of Hanoi Tower code VHDL——JK trigger It's over , Starting salary 30k