How do you make the right area of visibility?



  • In the Jquery library, there is a single feature that the code fragment takes an anonymous variable and is transmitted as an argument of function.

    $(function(){ ///... })
    

    The question is... How did they do that? I made the following fragment:

    function Lib(func){
      var a = 12;
      return func();
    }
    

    Lib(function(){ console.log(a); });

    But variable a Not in the field of visibility... How to make the anonymous function a variable a and in general all methods and characteristics of the function Lib♪ I wanted to set up a set of functions (to be accessible only internally) Lib

     Lib(function(){ console.log(a); });

    I understand there's another option for implementation, but it's the jQuery style.



  • function Lib(func){
      var a = 12;
      return func(a);
    }
    
    Lib(function(a){ console.log(a); });
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2