Closure
-
What is Closures
- 1 appreciated: closures are nested internal function
- 2 understood that: the closure comprising variable referenced objects (function)
-
Closure conditions are generated
- Nested functions
- Subroutine call the parent function data
- Father function is called (subroutine does not necessarily need to be called, you can only perform the function definition)
-
Common closures
- A function of performing another function return value
- A transfer function as an argument another function
-
Closure of the life cycle
- When you create a function definition is executed inline function
- Assignment destruction is null
-
Shortcoming
- Memory Leak
- cause:
- Unexpected global variables are not destroyed
- Closure of undestroyed
- The timer callback function is not destroyed
- Way to prevent
- Timely processing
- Less closure
- cause:
- Memory overflow
- A large number of memory leaks easily lead to memory overflow
- Memory Leak