Posted By

brianyang on 09/01/09


Tagged

closure functions defined referencing


Versions (?)

closure


 / Published in: JavaScript
 

When a function is defined in another function and it has access to the outer function's context even after the outer function returns.

  1. function outerFunction(someNum) {
  2. var someString = 'milk';
  3. var content = document.getElementById('content');
  4. function innerFunction() {
  5. content.innerHTML = someNum + ': ' + someString;
  6. content = null; // IE memory leak for DOM reference
  7. }
  8. innerFunction();
  9. }
  10.  
  11. outerFunction(1);

Report this snippet  

You need to login to post a comment.