Using Self Calling Anonymous Functions and $(document).ready

后端 未结 3 1443
-上瘾入骨i
-上瘾入骨i 2021-02-04 17:50

I just recently learned about self calling anonymous functions. Some snippets of code that I came across used the self calling function along with the $(document).ready. It se

3条回答
  •  臣服心动
    2021-02-04 18:41

    The only reason you would introduce another closure is to introduce another scope boundary for loading / protecting global objects such as $.

    For Example:

    $(document).ready(function(){
    
        // Do upper scope things.
    
        (function(){
    
            // Do lower scope things.
    
        })();
    
    });
    

    Based on you saying you have recently learning about this stuff I assume you are relativly new to JavaScript.

    I have put together a blog post that might help explaining some of the basic concepts form the point of view of a newcomer to JavaScript, including function scope. http://bit.ly/tLkykX

提交回复
热议问题