JS_16 closure

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

    1. Nested functions
    2. Subroutine call the parent function data
    3. 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
    • Memory overflow
      • A large number of memory leaks easily lead to memory overflow
Published 62 original articles · won praise 33 · views 10000 +

Guess you like

Origin blog.csdn.net/zjbyough/article/details/95244133