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,
How to prevent Mac put to sleep ? Tell you 4 This is an effective way be based on C# Students' grades / mis solve element-ui The drop-down box of has a value but cannot be selected Student information management system source code -C language VR,AR and MR The difference between these technologies 【 Data structure and algorithm 6】 Stack implementation of comprehensive calculator utilize python Yes monkey Automatic log analysis Laya Wechat games sub package loading Alibaba enterprise email smtp set up ( practice )【Java Details of knowledge points 3】 Serializable and Deserialize