First, we should explain the characteristics of the closure, so we should better understand the two features of the closure: 1. As a reference to a function variable-when the function returns, it is in the active state. 2. A closure is a stack that does not release resources when a function returns. In fact, the above two points can be merged, that is, when the closure function returns, the internal variables of the function are activated,
First, we should explain the characteristics of the closure, so we should better understand the two features of the closure: 1. As a reference to a function variable-when the function returns, it is in the active state. 2. A closure is a stack that does not release resources when a function returns. In fact, the above two points can be merged, that is, when the closure function returns, the internal variables of the function are activated,
We should first explain the characteristics of the closure to better understand it.
Closure has two features:
1. As a reference to a function variable-when a function is returned, it is activated.
2. A closure is a stack that does not release resources when a function returns.
In fact, the above two points can be merged, that is, when the closure function returns, the internal variables of the function are activated, and the stack zone of the function is retained.
Original address: Stupid bird flying technology sharing website http://www.sucker-fly.com/archives/519 <无>
function a(){ var i=0; function b(){ alert(++i); } return b; } var c = a(); c();